use strict; use warnings; use Win32::GUI(); my $window = new Win32::GUI::DialogBox( -width => 520, -height => 580, ); $window->Show(); my $entry = $window->AddTextfield( -size => [440,25], ); $entry->SetFocus; my $button = $window->AddButton( -name => 'button', -text => 'Search', -left => 448, -size =>[60,25], -ok => 1, ); my $display_field = $window->AddTextfield( -top => 30, -size => [513,513], -vscroll => 1, -multiline => 1, ); Win32::GUI::Dialog; sub button_Click { my $now = time; my $file = "./data"; #text file about the size of 30 MB open my $data, '<', $file or die "Open failed: $!"; $display_field->SelectAll(); $display_field->Clear(); my $query = $entry->Text; while (<$data>) { $display_field->Append($_) if /$query/i; } $now = time - $now; my $time = sprintf("\r\nTotal running time: %02d:%02d:%02d\r\n", int($now / 3600), int(($now % 3600) / 60), int($now % 60)); $display_field->Append($time); } #### use strict; use warnings; use Wx qw(:everything); my ($window, $entry, $display_field); package MyApp; use base 'Wx::App'; use Wx qw(:everything); sub OnInit { $window = Wx::Frame->new( undef, -1, '', [0,0], [520,580], ); $entry = Wx::TextCtrl->new( $window, -1, "", [0, 0], [408,-1], ); my $button = Wx::Button->new( $window, -1, "Search", [428,0], ); $display_field = Wx::TextCtrl->new( $window, -1, "", [0, 30], [508,513], wxTE_MULTILINE, ); Wx::Event::EVT_BUTTON( $button, -1, \&button_click,); sub button_click { my $now = time; #text file encoded in GB2312 about the size of 30 MB... #containing English and Chinese characters my $file = "./data"; open my $data, '<', $file or die "Open failed: $!"; $display_field->Clear; $display_field->Update; my $query = $entry->GetValue(); while(<$data>){ if(/$query/i){ $display_field->AppendText($_); $window->Update; } } $now = time - $now; my $time = sprintf("\n\nTotal running time: %02d:%02d:%02d\n\n", int($now / 3600), int(($now % 3600) / 60), int($now % 60)); $display_field->AppendText($time); } $window->Show; } MyApp->new->MainLoop; #### use Tk; use strict; use warnings; my $window = MainWindow -> new(); $window->geometry("520x580"); my $entry_frame = $window -> Frame()->pack(-side => "top"); my $entry = $entry_frame -> Entry (-width => 53, ) -> pack(-side => 'left'); $entry -> bind(''=> \&button_Click); $entry -> focus; my $button = $entry_frame -> Button (-text => "Search", -command => \&button_Click ) -> pack (-side => 'right'); my $display_field = $window -> Scrolled("Text",-scrollbars => 'e', ) -> pack(-side => 'top',-fill => 'y', -expand => 1); sub button_Click { my $now = time; my $file = "./data"; #text file about the size of 30 MB open my $data, '<', $file or die "Open failed: $!"; $display_field->delete('0.0','end'); my $query = $entry->get(); while (<$data>) { if(/$query/i){ $display_field->insert("end",$_); $window->update; } } $now = time - $now; my $time = sprintf("\n\nTotal running time: %02d:%02d:%02d\n\n", int($now / 3600), int(($now % 3600) / 60), int($now % 60)); $display_field->insert('end',$time); } MainLoop; #### my $file = "./data"; #text file about the size of 30 MB open my $data, '<:encoding(euc-cn)', $file or die "Open failed: $!";