I posted a question the other day about variable interpolation in a regex and got a lot of good help, thanks. This question is about the actual GUI part of it. I'm using Tk, and it's installed ok, but when I run my script it dies when it checks the modifiers, or when it checks for the file opening without even opening the window! It's probably just a typo, but I've been looking at it too long to find it. Any help would be greatly appreciated...

#!/usr/bin/perl -w # #lsearch.pl -- GUI app # #to search through log (or just txt) # #files for a pattern. Done because # #NT doesn't have grep. # #-----------------------------------------------# use strict; use Tk; my $mw = MainWindow->new(); #----------Labels & Entries----------* my $f_label = $mw->Label(-text => 'Enter file for searching here:'); $f_label->pack(); my $f_entry = $mw->Entry; my $p_label = $mw->Label(-text => 'Enter pattern to search for here:') +; $p_label->pack(); my $p_entry = $mw->Entry; #------------------------------------* #----------Checkbuttons----------* my $cbI = ''; my $cbS = ''; my $cbX = ''; my $cbO = ''; $mw->Checkbutton(-text => 'ignore case', -variable => \$cbI, -onvalue => 'i', -offvalue => '')->pack(); $mw->Checkbutton(-text => 'periods match newlines', -variable => \$cbS, -onvalue => 's', -offvalue => '')->pack(); $mw->Checkbutton(-text => 'ignore whitespace', -variable => \$cbX, -onvalue => 'x', -offvalue => '')->pack(); $mw->Checkbutton(-text => 'compile RE once only', -variable => \$cbO, -onvalue => 'o', -offvalue => '')->pack(); #------------------------------* #----------Action Buttons----------* my $s_button = $mw->Button(-text => 'Search', -command => \&search(get +_cb_values()) ); $s_button->pack(); my $x_button = $mw->Button(-text => 'Close', -command => sub {exit}); $x_button->pack(); #----------------------------------* #----------Text Area----------* my $output = $mw->Scrolled('Text', -width => 30, -height => 15, -scrollbars => 'se')->pack(); #-----------------------------* MainLoop; #----------Subroutines----------* sub search{ my $m = shift || ''; my $f = $f_entry->get(); my $p = $p_entry->get(); my $results; $p =~ s/([^\w\s\\|()[\]{}^\$~+?.])/\\$1/g; my $re = eval "qr/$p/$m"; die "Eval failed $@\n" if $@; open(FH, $f) or die "Couldn't open that file: $!"; while(<FH>){ if($_ =~ $re){ $results .= $_; } } close FH; display($results); } sub get_cb_values{ my $values = $cbI . $cbS . $cbX . $cbO; die "illegal mods" unless $values =~ m/^[ismxo\S]\z/; return $values; } sub display{ my $stuff = shift; $output->configure(-state => 'normal'); $output->delete('1.0', 'end'); $output->insert('end', "$stuff"); $output->configure(-state => 'disabled'); } #-------------------------------*

In reply to Follow-up on wimpy GUI search script... by derek3000

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.