develooper Front page | perl.beginners | Postings from November 2009

Re: push coomand on hash variables

Thread Previous
From:
John W. Krahn
Date:
November 12, 2009 02:19
Subject:
Re: push coomand on hash variables
Message ID:
4AFBE138.6090808@shaw.ca
Anant Gupta wrote:
> ..
> use strict;
> ..
> 
> my %hash;
> my $abc;
> my $count;
> while(defined($ARGV[$count]))
> {
>     push(@hash{$abc},$ARGV[$count]);
> }
> 
> Can't i use this
> 
> The error is "Type of arg 1 must be array not hash element ..."

@hash{$abc} is a hash slice.  You probably want @{$hash{$abc}}.




John
-- 
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity.               -- Damian Conway

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About