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 feature called autovivification, that usually Does The
Right Thing to create whatever you are trying to create.

Here is a tested full example from your original post:

<code>
#!/usr/bin/perl

use strict;
use warnings;


my @dirArray = qw(
abcdStuff1
acdeStuff1
abcdStuff2
aaaaStuff2
acdeStuff2
aaaaStuff1
);

my %dirHash = ();

foreach my $item(@dirArray) {
    my $prefix = substr($item, 0,4);
    push @{$dirHash{$prefix}}, $item;
}

use Data::Dumper;
print Data::Dumper->Dump([EMAIL PROTECTED], \%dirHash], [qw(*dirArray
*dirHash)]);
</code>

-- 
Alan F. Dickey - Interaction and Realization
http://www.intac.com/~afdickey
mailto:[EMAIL PROTECTED]
VOX: 908-273-3232 Cell: 908-334-0932

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to