On 21 Jun 2004, you wrote in perl.beginners:

> Have a question regarding hashes. Lets say I wanted a list as one of
> the values in my hash for the reason that I would want to constantly
> push values into that list. ..
> $dataHash{"$fileName"}{count} = 1;
> $dataHash{"$fileName"}{increment} = push(@array,$fileNumber);
> ###PROBLEM HERE!
> $dataHash{"$fileName"}{extension} = $fileExtension;
> 
> How would I push some data into the $dataHash{"$fileName"}{increment}
> ??? Do I have specify that$dataHash{"$fileName"}{increment} will equal
> a list previous to this???
> 
> Thanks in advance for reading this response.
> 
> -T
> 
> _________________________________________________________________
> FREE pop-up blocking with the new MSN Toolbar – get it now! 
> http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/
> 

Just treat that part of your hash as a list:
push(@{$dataHash{$fileName}{increment}}, $fileNumber);

Here's a small example:

use strict;
use Data::Dumper;

my %dataHash;
my $fileName = 'afile.txt';
my @fileNumbers = qw(1 2 3);

foreach my $fileNumber (@fileNumbers) {
    push(@{$dataHash{$fileName}{increment}}, $fileNumber);
}

print Dumper(\%dataHash);

__END__

Data::Dumper is nice to use when you want to see what's in a complex data structure. 
Output is something like this:

$VAR1 = {
          'afile.txt' => {
                           'increment' => [
                                            '1',
                                            '2',
                                            '3'
                                          ]
                         }
        };


Notice the [ ... ] value for 'incremet' shows you that it is a list.

-Scott

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to