Hi all,
Here is what I have so far for this...
use strict;
# cannot remember syntax for "use warnings but no 'uninitialized'
my ($album, @upc_list);
my @data_src = parse_data();
print "Data Source: ";
print "$_ " foreach @data_src;
print "\n";
# test
my $album1 = $album->{$upc_list[0]};
foreach ([EMAIL PROTECTED]>{track}} -1) {
print " $album1->{track}[$_] on $album1->{name} is sung by
$album1->{artist}[$_]";
print "\n";
}
# use Data::Dumper;
# print Dumper(\$album);
## SUBROUTINES ##
sub parse_data {
my (@data_src, @headings);
while(<DATA>) {
next if /^K\|+/; # skip first line
chomp;
# get data source information
if (/^\|/ and scalar @data_src < 2) {
my (undef, $tmp) = split (/\|[^\w"]+/, $_, 2);
$tmp =~ s/^"?([^"|]+)"?.*/$1/;
push @data_src, $tmp if $tmp;
next;
}
# get header
if (/^[^|]/ and [EMAIL PROTECTED]) {
@headings = split(/"?[|"]+"?/, $_, 5);
pop @headings; shift @headings;
foreach (@headings) {
my($name, $upc) = split (/ UPC#: /);
$album->{$upc}{'name'} = $name;
push @upc_list, $upc;
}
next;
}
# 'empty' lines
next if /^\|+/;
parse_song_artist($_);
}
return @data_src;
}
sub parse_song_artist {
# grab song/artist pairs for each album (3 pairs per line in data)
### See question below regarding these three lines...
my @pairs = split /\|+/, shift, 6;
my @songs = @pairs[0, 2, 4];
my @artists = @pairs[1, 3, 5];
foreach (0..2) {
push @{$album->{$upc_list[$_]}{'track'}}, $songs[$_];
push @{$album->{$upc_list[$_]}{'artist'}}, $artists[$_];
}
}
__END__
Where I am stuck is on the question:
Given an @array such as
("Title of Song", "Artist", "Title", "Another Artist", "etc"),
is there an easy way to strip out the quotation marks. This
sounds like something for a map function -- which I'm willing
to work out for myself if you all think this is the best way.
The arrays come from the line split mentioned just above (see
"###" line). I'm splitting on "|||"s.
-Kevin
--
Kevin Pfeiffer
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]