Perl Data Structure Problem

Soldato
Joined
26 Oct 2002
Posts
3,753
Location
Surrey
Hi All,

I am having problems creating a hash of arrays. I want a hash that is indexed by ""allowed_site" with the array populated by "@sub_glob" but it just doesn't seem to work :(

Code:
foreach my $allowed_site (@allowed_sites) {
    chdir $allowed_site or warn "Couldn't cd to $allowed_site $!\n";
    my @sub_glob = glob "subweb_*";
    print "@sub_glob\n";
    print "$allowed_site and @sub_glob\n";
    my $web2sub{$allowed_site} = [ @sub_glob ];
    chdir $www_base;
}

I get the following error:

Code:
# /root/perl/mk_www_users.pl
syntax error at /root/perl/mk_www_users.pl line 262, near "$web2sub{"
syntax error at /root/perl/mk_www_users.pl line 264, near "}"
Execution of /root/perl/mk_www_users.pl aborted due to compilation errors.

Any ideas what I'm doing wrong? The syntax for my HoA looks correct to me ...
 
surely :
Code:
my %web2sub;
foreach my $allowed_site (@allowed_sites) {
    chdir $allowed_site or warn "Couldn't cd to $allowed_site $!\n";
    my @sub_glob = glob "subweb_*";
    print "@sub_glob\n";
    print "$allowed_site and @sub_glob\n";
    $web2sub{$allowed_site} = [ @sub_glob ];
    chdir $www_base;
}
 
Back
Top Bottom