#!/usr/bin/perl use Getopt::Long; use Tk; GetOptions("level=s",\$level); $classlevel = "intro" unless $classlevel; readData($classlevel); buildGUI(); update(); # start with all non-matches MainLoop(); sub buildGUI { $m = new MainWindow(); $f1 = $m->Frame(); $f1->pack(); $reprompt = $f1->Label(-text=>"Enter RE:"); $reprompt->pack(-side=>'left'); $refield = $f1->Entry(-textvariable=>\$RE_text); $refield->pack(-side=>'left'); $refield->bind('',\&update); $case = $f1->Checkbutton(-text=>"Ignore Case",-variable=>\$ic); $case->pack(-side=>"right",-anchor=>'e'); $case->bind('<1>',\&update); $case->bind('',\&update); $f2 = $m->Frame(); $f2->pack(); $f2a = $f2->Frame(); $f2a->pack(-side=>'left'); $f2b = $f2->Frame(); $f2b->pack(-side=>'left'); $matchlabel = $f2a->Label(-text=>"Matching Lines"); $matchlabel->pack(); $matches = $f2a->Scrolled("Text",-scrollbars=>"oe",-height=>10,-width=>40); $matches->pack(); $nonmatchlabel = $f2b->Label(-text=>"Non-Matching Lines"); $nonmatchlabel->pack(); $nonmatches = $f2b->Scrolled("Text",-scrollbars=>"oe", -height=>10,-width=>40); $nonmatches->pack(); $f3 = $m->Frame(); $f3->pack(); $bye = $f3->Button(-text=>"Quit",-command=>sub { $m->destroy(); }); $bye->pack(-side=>"left"); } # fix to read any file... sub readData { my $level = shift; while () { push(@lines,$_) if /^begin ${level}$/../^end ${level}$/; } shift(@lines); # skip 1st and last lines pop(@lines); } sub update { my $pat; if ($RE_text) { $pat = $ic?"(?i)$RE_text":$RE_text; $matches->delete("1.0",'end'); $matches->insert('end',join("",grep(/$pat/,@lines))); $nonmatches->delete("1.0",'end'); $nonmatches->insert('end',join("",grep(($_ !~ /$pat/),@lines))); } else { $matches->delete("1.0",'end'); $nonmatches->delete("1.0",'end'); $nonmatches->insert('end',join("",@lines)); } } __END__ begin intro This is a test abc123abc Potato Potatoe apple pineapple applesauce Miss Susie Creamcheese In the 1970s, flared pants were popular pertinent data are being made up ^######^ Showstring Parsippany is not in Mississippi 1000 application data foo bar blah 1,2,3,4 MacIntosh 123A Pleeeeeeze McDonald MacTurk I don't care for that McDougall issississississississississississ end intro begin advanced end advanced :endofprog