in reply to Re: Perl Hashes, keys under keys (I think)?
in thread Perl Hashes, keys under keys (I think)?


hbm,

Hey thanks for the reply. I did try exactly that but the way the output looked didn't seem right. It looked liked it added them as elements instead of keys to those elements. But I could have just misunderstood.

Ok so if I do that this is my output:
$records{"$owner_record[1]"} = [ USER => "$owner_record[5]", FILENAME => "$owner_record[0]", PID => "$owner_record[6]", TIME => "$owner_record[9]", DATE => (join ":", "$owner_record[10] $owner_record[11]"), + ELAPSED => [] ]; ___OUTPUT___ $VAR1 = { '999?SheetMusic' => [ 'USER', 'bill', 'FILENAME', '/ud/NEW-PrOdUcTs/NWA', 'PID', '5151515', 'TIME', '10:51:00', 'DATE', 'Sep 16', 'ELAPSED', [] ], '667!NEWPRODUCT' => [ 'USER', 'matthew', 'FILENAME', '/ud/QC-PROD/NWO', 'PID', '5555555', 'TIME', '10:25:00', 'DATE', 'Sep 16', 'ELAPSED', [] ], '001!SCHEDULE' => [ 'USER', 'richard', 'FILENAME', '/ud/QC-DATA/CONTROL', 'PID', '5005444', 'TIME', '10:50:44', 'DATE', 'Sep 16', 'ELAPSED', [] ] };


Thanks,
Matt


.

Replies are listed 'Best First'.
Re^3: Perl Hashes, keys under keys (I think)?
by duyet (Friar) on Sep 19, 2011 at 15:56 UTC

    Remember that [] is used to reference to an array element and a {} is for a hash. So you need to change your code to:

    # v $records{"$owner_record[1]"} = { USER => "$owner_record[5]", FILENAME => "$owner_record[0]", PID => "$owner_record[6]", TIME => "$owner_record[9]", DATE => (join ":", "$owner_record[10] $owner_record[11]"), + ELAPSED => [] }; # ^