Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Help on parsing

by aaroon (Initiate)
on Nov 17, 2010 at 19:52 UTC ( #872043=perlquestion: print w/ replies, xml ) Need Help??
aaroon has asked for the wisdom of the Perl Monks concerning the following question:

I need help in matching a text file and store its content in the following way

Content is

JAN| 
graph|104| 
success|100| 
on_time|100| 
environment|1| 
builder|3| 
design|0| 
FEB| 
graph|95| 
success|100| 
on_time|100| 
environment|1| 
builder|3| 
design|0| 
. 
. 
. 
. 
goes till DEC

all i want is i would have to check if its JAN, FEB or MAR and the copy that in a month array and then i will have a input argument say "graph" so it will match with the graph keyword and pick all the graph values of all the month and put it in a separate array say @data_arr. Any help on this would be greatly appreciated... Thanks

Comment on Help on parsing
Re: Help on parsing
by roboticus (Canon) on Nov 17, 2010 at 20:22 UTC
      Thanks...I am not in school btw....and this is not class project by any chance....
        Below is something to start with. Requires some effort from your side to completion. Good Luck!
        use strict; use Data::Dumper; my %hash; my $header_info; DAT: while (<DATA>) { next if !length($_); # ignore empty lines if ($_ =~ /^([A-Z]+)\|/) # capture the header { ($header_info) = $1; next DAT; } my($key, $value) = split /\|/, $_; $hash{$header_info}{$key} = $value; } #print Dumper(\%hash); for my $key1 (sort keys %hash) { for my $key2 ( sort keys %{ $hash{$key1} }) { print "$key1:$key2:$hash{$key1}{$key2}\t"; } print "\n"; } __DATA__ JAN| graph|104| success|100| on_time|100| environment|1| builder|3| design|0| FEB| graph|95| success|100| on_time|100| environment|1| builder|3| design|0|

        That's good--but code to spec isn't free. Most of the contributors here get _paid_ to write code. The harder *you* work, the more help you'll get. The more you ask other people to do the coding for you, the more you'll get sent to read the documentation.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2014-12-25 21:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (163 votes), past polls