How can i combine both?

This code I wish to put on `push_Start` sub function and will display the `$__->read` to the `$txt1` widget.
How should i make both or them work together?

And the `for foreach (@pending)` part, i just want to get the IP address and port? This condition :

if (@pending =~ /((\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):(\d{1,5}))/)0

does not make it work?

I'm summary my code

I had try two way but it does not work... `$_->read` isn't a file handle at sub push_button so how to correct it? when i click the Start Button it should be print out the result on text area.
#!/usr/local/bin/perl use Tk; use File::Tail; <br> #Main Window<br/> <br> my $mw = new MainWindow;<br/> <br> $mw-> title ("Packet Analyzer Tool");<br/> <br> my $frm_4 = $frm_3 -> Frame(-relief => 'groove', -borderwidth +=>2) -> pack(-side => "left");<br/> <br> my $but1 = $frm_1 -> Button(-text => "Start", -command =>\&push_start) -> pack(-side => "left", -anchor => 'nw', -ipadx => 30, -i +pady => 35);<br/> <br> my $txt1 = $frm_4 -> Text(-width => 60, -height =>20,-state => + "disable") -> pack(-side =>"left",-anchor => 's'); my $srl = $frm_4 -> Scrollbar(-orient=>'v', -command =>[yview => $ +txt]);<br/> <br> $txt1 -> configure(-yscrollcommand =>['set',$srl]);<br/> <br> #$txt -> insert('end', "XXX"); //display text<br/> <br> $txt1 -> grid(-row=>1, -column=>1);<br/> <br> $srl -> grid(-row=>1, -column=>2,-sticky=>"ns");<br/> <br>MainLoop;<br/> <br> #Executed START BUTTON<br/> <br> sub push_start<br/> <br> {<br/> <br> chdir( "/var/log/snort");<br/> <br> foreach my $fol(glob "*.*.*.*")<br/> <br> {<br/> <br> print "Opening $fol\n";<br/> <br> chdir("/var/log/snort/$fol");<br/> <br>foreach my $subfile(glob "*:*")<br/> <br>{<br/> <br>print "opening $subfile\n";<br/> <br> push(@files,File::Tail->new(name=>"$subfile",debug=>$d +ebug));<br/> <br> }<br/> <br> while (1)<br/> <br> {<br/> <br> ($nfound,$timeleft,@pending)= File::Tail::select(undef +,undef,undef,$timeout,@files);<br/> <br> unless ($nfound)<br/> <br> {<br/> <br> print "Nothing to print \n"; <br/><br> } <br/> <br> else <br/> <br> {<br/> <br> foreach(@pending)<br/> <br> {<br/> <br>$txt1 ->insert('end', $_->read);<br/> <br> }<br/> <br>}<br/> <br>}<br/> <br>}<br/> }

The second way is wrote as below, `tie *STDOUT ref $txt1, $txt1;` i refer to this documentation(http://search.cpan.org/~srezic/Tk-804.029/pod/Text.pod#___top) But it does not work either.
#!/usr/local/bin/perl <br> use Tk;<br/> <br> use File::Tail;<br/> <br> #Main Window<br/> <br> my $mw = new MainWindow;<br/> <br> $mw-> title ("Packet Analyzer Tool");<br/> <br> my $frm_4 = $frm_3 -> Frame(-relief => 'groove', -borderwidth +=>2) -> pack(-side => "left");<br/> <br> my $but1 = $frm_1 -> Button(-text => "Start", -command =>\&push_start) -> pack(-side => "left", -anchor => 'nw', -ipadx => 30, -i +pady => 35);<br/> <br> my $txt1 = $frm_4 -> Text(-width => 60, -height =>20,-state => + "disable") -> pack(-side =>"left",-anchor => 's'); my $srl = $frm_4 -> Scrollbar(-orient=>'v', -command =>[yview => $ +txt]);<br/> <br> $txt1 -> configure(-yscrollcommand =>['set',$srl]);<br/> <br> #$txt -> insert('end', "XXX"); //display text<br/> <br> $txt1 -> grid(-row=>1, -column=>1);<br/> <br> $srl -> grid(-row=>1, -column=>2,-sticky=>"ns");<br/> <br>MainLoop;<br/> <br> #Executed START BUTTON<br/> <br> sub push_start<br/> <br> {<br/> <br> chdir( "/var/log/snort");<br/> <br> foreach my $fol(glob "*.*.*.*")<br/> <br> {<br/> <br> print "Opening $fol\n";<br/> <br> chdir("/var/log/snort/$fol");<br/> <br>foreach my $subfile(glob "*:*")<br/> <br>{<br/> <br>print "opening $subfile\n";<br/> <br> push(@files,File::Tail->new(name=>"$subfile",debug=>$d +ebug));<br/> <br> }<br/> <br> while (1)<br/> <br> {<br/> <br> ($nfound,$timeleft,@pending)= File::Tail::select(undef +,undef,undef,$timeout,@files);<br/> <br> unless ($nfound)<br/> <br> {<br/> <br> print "Nothing to print \n"; <br/><br> } <br/> <br> else <br/> <br> {<br/> <br> foreach(@pending)<br/> <br> {<br/> <br>tie *STDOUT ref $txt1, $txt1;<br/> <br>print $_->read;<br/> <br> }<br/> <br>}<br/> <br>}<br/> <br>}<br/> }

In reply to combine perl/tk and file::tail::select by terrance

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.