Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^4: Complicated Hash with array

by inblosam (Monk)
on Aug 08, 2006 at 19:46 UTC ( [id://566236]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Complicated Hash with array
in thread Complicated Hash with array

Works perfectly! Thanks Grandfather and Hofmator!!

The full code is included here for ease...
#!/usr/bin/perl -w use strict; use Data::Dumper; my $rawdata = qq| <COLUMNS>~ItemName1~ItemName2~ItemName3~ItemName4~ItemName5~</COLUMNS> <DATA>~Apple~Orange~Banana~Pear~Watermelon~</DATA> <DATA>~Blue~Red~Yellow~Brown~Purple~</DATA> <DATA>~Uno~Dos~Tres~Cuatro~Cinco~</DATA> |; my @datalines = grep {length} split "\n",$rawdata; my @listings; my $header; foreach my $line (@datalines) { if ($line =~ /^<COLUMNS>(.+)<\/COLUMNS>/) { $header = $1; } elsif ($line =~ /^<DATA>(.+)<\/DATA>/) { push(@listings, $1); } } my %hoa; my @keys = grep {length} split '~', $header; for my $listing (@listings) { my @list = grep {length} split '~', $listing; push @{$hoa{$keys[$_]}}, $list[$_] for 0..$#keys; } for my $listing (@listings) { my @list = grep {length} split '~', $listing; my %data; @data{@keys} = @list; print "Item1 is ", $data{'ItemName1'}, ", "; print "Item2 is ", $data{'ItemName2'}, ", "; print "Item3 is ", $data{'ItemName3'}, "\n"; }


Michael Jensen

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-19 22:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found