I have some data that has the column titles (ItemName1...) for each of the objects (Apple, Orange, ....), and then multiple lines of objects that correspond to the column titles.
What I am trying to do, but don't know where to go next, is to put all the data in a sort of hash array. The column titles would be the keys of the hash, but there would be a separate line for each line of data/objects.
This is the code where I am at so far:
#!/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 = split("\n",$rawdata);
my @listings;
my $header;
foreach my $line (@datalines) {
if ($line =~ /^<COLUMNS>(.+)<\/COLUMNS>/xg) {
$header = $1;
} elsif ($line =~ /^<DATA>(.+)<\/DATA>/xg) {
push(@listings, $1);
}
}
print Dumper(\$header);
print Dumper(\@listings);
Thanks for your help!