shortyfw06 has asked for the wisdom of the Perl Monks concerning the following question:
Can someone please guide me through this file parsing example? I am trying to search for the last occurence of a particular line in a file. Then skip three lines. Next, I want to create a hash starting at the fourth line and ending when a blank line is found. An example of the test is this. Here is an example of the file and my code so far. Thanks!
FAILURE CRITERIA PER PLY DIST ANGLE PLY FAILURE NUMBERS 1 2 SHEAR 0.000 0.00 -45.00 0.238 0.282 -1.459 0.000 0.00 0.00 0.971 1.369 0.004 0.000 5.00 -45.00 0.475 0.142 -1.585 0.000 5.00 0.00 1.003 1.531 -0.274 0.000 10.00 -45.00 0.721 0.037 -1.623 FAILURE CRITERIA PER PLY DIST ANGLE PLY FAILURE NUMBERS 1 2 SHEAR 0.000 0.00 -45.00 0.247 0.293 -1.514 0.000 0.00 0.00 1.008 1.422 0.004 0.000 5.00 -45.00 0.493 0.147 -1.645 0.000 5.00 0.00 1.042 1.589 -0.284 #!usr/bin/perl use Tk; use Cwd; use strict; use warnings; # ###################################################################### +##################### # GUI Building ###################################################################### +##################### # # Create Main Window my $mw=new MainWindow; my $filename; my $string1; my $string2; my $line; my $n; my $test; my $skip1; my $skip2; my $skip3; my %temp; my $ms_button = $mw->Button(-text=>"MS", -command=> \&BJSFM_MS)->pack(); MainLoop; sub BJSFM_MS { $filename="BJSFM_out.prn"; open(OUTPUT_FILE, "< $filename") or die "Can't find $filename!"; $string1="FAILURE CRITERIA PER PLY"; $string2="AUTOMATIC SEARCH FOR FAILURE"; while ($line = <OUTPUT_FILE>) { if ($line =~ $string1) { $skip1 = <OUTPUT_FILE>; $skip2 = <OUTPUT_FILE>; $skip3 = <OUTPUT_FILE>; $n=1; do { $temp{$n} = <OUTPUT_FILE>; n++; } until ???????? Im not sure here? } } close(OUTPUT_FILE); print (%temp); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: File Parsing
by choroba (Cardinal) on May 31, 2012 at 16:14 UTC | |
by shortyfw06 (Beadle) on Jun 14, 2012 at 14:51 UTC | |
|
Re: File Parsing
by thundergnat (Deacon) on May 31, 2012 at 16:48 UTC | |
by shortyfw06 (Beadle) on May 31, 2012 at 20:45 UTC | |
by thundergnat (Deacon) on Jun 01, 2012 at 14:30 UTC |