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/>
}