J. Patrick Lanigan writes ..
>I haven't quite sorted out the more complex data structure in perl yet.
>Anyhow, I need to take the following hash of arrays...
you have some very confusing code there .. so let's do it one bit at a time
>my %tracks = ();
create a hash called tracks with zero elements
>push @{$tracks{$filename}},
> $_, # tracks.filename
> $File::Find::dir . '/', # tracks.filepath
> $artist, # artist.artist_name
> $album, # album.title
> $tracknum, # tracks.track_num
> $title, # tracks.title
> $genre; # tracks.title
create a new element of the tracks hash using the value of the variable
$filename as the key
treat that new element as an array reference and push a bunch of values onto
it
assume for a secont that $filename has the value 'file1' .. at this point in
the code you have something like the following structure
%tracks = ( file1 => [ $_, 'some/path/', 'artist_name', 'etc...' ] );
I didn't continue it .. but as well as the artist name you've got the album
title, the track number, title, and genre in there .. you get the drift
but you've got only one member of the %tracks hash .. it's key is the value
of $filename and it's value is an array reference as above
>for my $row ( keys %tracks ){
so now we grab the keys of %tracks - of which there is only one - 'file1' in
our example .. then we stick that into $row
> (my $qualified_filename, my $filename, my $filepath,
>$artist, $album, $tracknum, $title, $genre) =
> "$row @{ $tracks{$row} }";
now we create a string containing the key ('file1') then a space and then
the values of the array referred to by $tracks{file1}
it's a single value - so it goes into the first element of the lvalue list -
ie. $qualified_filename
the following code would have done EXACTLY the same as what you've done
above
my %tracks;
$tracks{$filename} = [ $_,
$File::Find::dir . '/',
$artist,
$album,
$tracknum,
$title,
$genre,
];
my $qualified_name = "$filename @{ $tracks{$filename} }";
so .. as you can tell - you'll have to explain a bit more about what you're
trying to do .. because it's really not clear
--
jason king
A Canadian law states that citizens may not publicly remove bandages.
- http://dumblaws.com/