in reply to File Parsing
chorobas solution and commentary is excellent; I don't disagree with any of it. I offer this as an alternate possible solution. (I was doing this before I saw that was posted.) Here I slurp the file in by paragraphs then pick out the lines I want to save.
#!usr/bin/perl use strict; use warnings; use Tk; use Cwd; use Data::Dumper; # ###################################################################### +##################### # GUI Building ###################################################################### +##################### # # Create Main Window my $mw = MainWindow->new; my $n = 0; my %temp; my $ms_button = $mw->Button( -text=>"MS", -command=> \&BJSFM_MS )->pack(); MainLoop; sub BJSFM_MS { my $filename = 'BJSFM_out.prn'; #open my $infile, '<', $filename or die "Can't open $filename! $!" +; my $infile = *DATA; local $/="FAILURE CRITERIA PER PLY\n"; while (my $paragraph = <$infile>) { chomp $paragraph; $paragraph =~ s/^\s+\n|\s+$//g; my @lines = split "\n", $paragraph; next if @lines < 4; map {$temp{$n++} = $_ } @lines[3..$#lines]; } close $infile; print Dumper \%temp; } __DATA__ 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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: File Parsing
by shortyfw06 (Beadle) on May 31, 2012 at 20:45 UTC | |
by thundergnat (Deacon) on Jun 01, 2012 at 14:30 UTC |
In Section
Seekers of Perl Wisdom