Daniel Gross [EMAIL PROTECTED] writes:
I running into problems again: This time I'd like to fill a hash
with arrays, however, the following push command generates a
syntax error. Any idea why
My %dirHash = ();
foreach my $item(@dirArray) {
$prefix = substr($item, 0,4);
push
. Discenza [mailto:[EMAIL PROTECTED]
Sent: Thursday, April 03, 2003 8:36 AM
To: Daniel Gross; [EMAIL PROTECTED]
Subject: RE: Hash of arrays
Daniel Gross wrote, on Thursday, April 03, 2003 08:34
: I running into problems again: This time I'd like to fill a hash with
: arrays, however, the following push
Daniel Gross wrote:
Seems to work. It doesn't generate a syntax error. So, value elements
within a hash are always references?
no, but they are always scalars :)
BTW, in your opinion would this also work when $dirHash{$prefix} is
undefined (i.e. when no key was defined yet?)
perl has a
Daniel Gross wrote, on Thursday, April 03, 2003 08:45
: push @{$dirHash{$prefix}}, $item;
: Seems to work. It doesn't generate a syntax error. So, value elements
: within a hash are always references?
:
: BTW, in your opinion would this also work when $dirHash{$prefix} is
: undefined (i.e.
# I have a program that gets a hash from an API call.
# the format of the hash is that each key corresponds to an
# array. The following code snippet illustrates the data:
$href-{One} = [1,2,3,4];
print ref($href).\n;
print ref($href-{One}).\n;
# I would like to simplify the syntax to use a
: Wednesday, January 16, 2002 10:43
To: 'Peter Eisengrein'; Perl-Win32-Users Mailing List (E-mail)
Subject: RE: hash of arrays
This is what you want...
foreach my $dn (keys %features)
{
my @features = @{$features{$dn}};
print $dn|;
foreach (@features
BINGO! Thanks Rob.
-Original Message-
From: Hanson, Robert [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, January 16, 2002 10:58
To: 'Peter Eisengrein'
Subject: RE: hash of arrays
Hmmm...
If $features{$dn} is a reference to an array you dereference
it like
- Original Message -
From: Peter Eisengrein [EMAIL PROTECTED]
That just adds a field to my output, like so:
7943641|ARRAY(0x1b9efb8)||
Perhaps I'm contructing it wrong? I'm doing it like this...
@_=$features{$dn};
push(@_,$line[1]);
$features{$dn}=\@_;
That's kind