Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Help on parsing

by roboticus (Chancellor)
on Nov 17, 2010 at 20:22 UTC ( #872048=note: print w/ replies, xml ) Need Help??

in reply to Help on parsing


Stuff to read: the split function, data types in perl, perl data structures cookbook, and (of course) your course notes.


Comment on Re: Help on parsing
Download Code
Replies are listed 'Best First'.
Re^2: Help on parsing
by aaroon (Initiate) on Nov 17, 2010 at 20:27 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?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2015-10-14 03:22 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (320 votes), past polls