Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: File Parsing

by shortyfw06 (Beadle)
on Jun 14, 2012 at 14:51 UTC ( #976228=note: print w/ replies, xml ) Need Help??


in reply to Re: File Parsing
in thread File Parsing

The example in the original post is one step in my overall goal. In moving forward, I think I do want a hash, however, the hash value for key 1 should be @array. Then the @array is undefined and the next match creates a new @array with is then the hash value for key 2. This process is repeated until all matches have been found in the file for each element in @headers. I am really struggling with this one.... I hope my explanation is clear. Here is my attempt at this.

#!usr/bin/perl use Tk; use Cwd; use strict; use warnings; # ###################################################################### +##################### # GUI Building ###################################################################### +##################### # # Create Main Window my $mw=new MainWindow; my $filename; my $line; my $n; my @headers = ("LAMINATE PROPERTIES", "LAMINATE STRESSES", "LAMINATE STRAINS", "CIRCUMFERENTIAL AND RADIAL STRESSES & STRAINS", "DISPLACEMENTS", "STRAINS PER PLY", "STRESSES PER PLY", "FAILURE CRITERIA PER PLY"); my $inner; my @array; my %hash; 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!"; $n=1; while ($line = <OUTPUT_FILE>) { if ($line =~ /$headers[$n-1]/) { undef @array; #This clears the previous two instances + of $string1 <OUTPUT_FILE> for 1..3; while ($inner = <OUTPUT_FILE>) { last if $inner =~ /^$/; push @array,$inner; } $hash{$n}=@array; $n++; } } close OUTPUT_FILE; print @array; print %hash; }


Comment on Re^2: File Parsing
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://976228]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (16)
As of 2014-09-02 12:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (22 votes), past polls