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;