jasonwolf has asked for the wisdom of the Perl Monks concerning the following question:
I am using ActiveState Perl on Windows, and I am coding a TK gui for a log file parser. I have the framework down, and boxes mapping to variables. I also have rough code down that parses through a file and returns values, but this does not work 100%. It only returns one line, which is the first line that is found; however, this works at my DOS prompt correctly, so I am not sure how I should fix the issue in my code.
#: TITLE : LOG VIEW #: BY : Jason ###################################################################### +########## use Tkx; Tkx::wm_title(".", "Log Viewer"); Tkx::ttk__frame(".c", -padding => "3 3 12 12"); Tkx::grid( ".c", -column => 0, -row => 0, -sticky => "nwes"); Tkx::grid_columnconfigure( ".", 0, -weight => 1); Tkx::grid_rowconfigure(".", 0, -weight => 1); #--- label for device Tkx::grid( Tkx::ttk__label(".c.devicelbl", -text => "DEVICE:"), -colum +n => 1, -row => 1, -sticky => "e"); #--- text box entry field #--- and label that is associated with textbox entry field Tkx::ttk__entry(".c.device", -width => 14, -textvariable => \$device); Tkx::grid(".c.device", -column => 2, -row => 1, -sticky => "we"); #--- label for start time field Tkx::grid( Tkx::ttk__label(".c.stimelbl", -text => "START TIME:"), -co +lumn => 1, -row => 2, -sticky => "e"); #--- start time field #--- start time field position Tkx::ttk__entry(".c.stime", -width => 10, -textvariable => \$stime); Tkx::grid(".c.stime", -column => 2, -row => 2, -sticky => "we"); #--- label for end field Tkx::grid( Tkx::ttk__label(".c.etimelbl", -text => "END TIME:"), -colu +mn => 3, -row => 2, -sticky => "e"); #--- end time field #--- end time field position Tkx::ttk__entry(".c.etime", -width => 10, -textvariable => \$etime); Tkx::grid(".c.etime", -column => 4, -row => 2, -sticky => "we"); #--- label for search field Tkx::grid( Tkx::ttk__label(".c.searchlbl", -text => "VALUE:"), -column + => 1, -row => 3, -sticky => "e"); #--- search field #--- search field location Tkx::ttk__entry(".c.search", -width => 50, -textvariable => \$value); Tkx::grid(".c.search", -column=> 2, -row => 3, -columnspan => 3, -stic +ky => "we"); #--- button Tkx::ttk__button(".c.run", -text => "RUN", -command => sub {sub_device +();}); Tkx::grid(".c.run", -column => 1, -row => 5, -columnspan => 4, -sticky + => "we"); # new Tkx::ttk__label(".c.calc", -textvariable => \$output_device); Tkx::grid(".c.calc", -column => 0, -row => 6, -columnspan => 12, -stic +ky => "nsew"); foreach (Tkx::SplitList(Tkx::winfo_children(".c"))) { Tkx::grid_configure($_, -padx => 5, -pady => 5); } # new #Tkx::focus(".c.device"); #Tkx::bind(".", "<Return>", sub {calculate();}); Tkx::MainLoop(); #===================================================================== +========== # SUBROUTINES #===================================================================== +========== #sub calculate { # $calc = $device; #} sub sub_device { # $output_device = $device; open FILE,"<data.txt" or die "Cannot read the file $filename: $!\n"; while ($line = <FILE>) { if ($line =~ /\b$device\b/i) { $output_device = $line; } } } sub sub_stime { $output_stime = $stime; } sub sub_etime { $output_etime = $etime; }
I am using the following line to display my search results
Tkx::ttk__label(".c.calc", -textvariable => \$output_device); Tkx::grid(".c.calc", -column => 0, -row => 6, -columnspan => 12, -stic +ky => "nsew");
However, I only get one entry in the above column and row. So, not sure what I am doing wrong. Here is a copy of my dummy data
#datafile.txt 192.168.13.1,items are locked 192.168.13.1, error 192.168.26.1, error this is an error output 192.168.26.1,items are output items are out put 192.168.26.3 error,100 lerror,101 45:ea:32:a1:b3:21 32:ae:12:15:15:00 AF:00:E3:43:32:AA, error data is invalid 32:ae:12:15:15:00
note - this will be used parse through Kiwi Syslog files, so syslog standard file will be used. My 'datafile.txt' is just dummy data for testing.
Not sure if I should use something different then modifying the text as I am doing. I also, suspect I will need a left>right scroll bar for output.
I am looking for different ways to program this application, and looking forward to talking shop about Perl programming, and strengthening my coding/scripting skills.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: text parser TkGUI ActiveState
by Anonymous Monk on Aug 11, 2015 at 23:05 UTC | |
by jasonwolf (Sexton) on Aug 12, 2015 at 12:46 UTC | |
by roboticus (Chancellor) on Aug 12, 2015 at 13:40 UTC |