in reply to Re: Array of Hashes
in thread Array of Hashes

Thanks that works!

<If you don't have duplicate hash keys, though, why are you using an array of hash refs?>
I will not have duplicate captureID's. But I want to record the data in the following table using some Perl data structure.

captureID | outputFileLocation| Filetype
------------|--------------------|---------
captureID1 | c:/temp/test.xml | 4
captureID2 | c:/test/temp.xml | 6 ......

In this captureID is unique. Is there any other way of handling this data other than array of hashes?

Replies are listed 'Best First'.
Re^3: Array of Hashes
by graff (Chancellor) on Sep 20, 2005 at 18:07 UTC
    Is there any other way of handling this data...

    Since all the "captureID" values are unique, and these are the values that you want to use for fetching information about a given entry, I guess the question is, "why use an array at all?" I think a HoH (or even a simple hash) would work just as well:

    my %outputFiles; sub setOutputFile { my ($id,$path,$type) = @_; # HoH method: $outputFiles{$id}{path} = $path; $outputFiles{$id}{type} = $type; # or, simple hash method: # $outputFiles{$id} = join "=:=", $type, $path; } sub getOutputFiles { my $id = shift; # HoH method: my $type = $outputFiles{$id}{type}; my $path = $outputFiles{$id}{path}; # or, simple hash method: # my ( $type, $path ) = split /=:=/, $outputFiles{$id}; # ... do something with $path and $type ... }