Re: push coomand on hash variables

2009-11-13 Thread Erez Schatz
2009/11/13 Anant Gupta : > ohhh ok. > Thanks for the help > > But there is an XML example using XML::Twig in which > the author has defined the hash as > my $hash={   'abc'=>'def'. >                     'ghi'=>'jkl', >                     'mnp'=>'pqr' >                  } > > I thought it is a refe

Re: push coomand on hash variables

2009-11-13 Thread Anant Gupta
ohhh ok. Thanks for the help But there is an XML example using XML::Twig in which the author has defined the hash as my $hash={ 'abc'=>'def'. 'ghi'=>'jkl', 'mnp'=>'pqr' } I thought it is a reference to a hash. Is it so? Can we directl

Re: push coomand on hash variables

2009-11-12 Thread John W. Krahn
Anant Gupta wrote: .. use strict; .. my %hash; my $abc; my $count; while(defined($ARGV[$count])) { push(@hash{$abc},$ARGV[$count]); } @ARGV gets its values from the command line so all its elements should be defined, unless you are using delete() on one of its elements. You are not chan

Re: push coomand on hash variables

2009-11-12 Thread Erez Schatz
2009/11/12 Anant Gupta : > my %hash; > my $abc; > my $count; > while(defined($ARGV[$count])) > { >    push(@hash{$abc},$ARGV[$count]); > } > > The error is "Type of arg 1 must be array not hash element ..." The error is correct, you can't "push" to a hash element. Question is, what exactly do you

Re: push coomand on hash variables

2009-11-12 Thread 兰花仙子
On Thu, Nov 12, 2009 at 6:01 PM, Anant Gupta wrote: > .. > use strict; > .. > > my %hash; > my $abc; > my $count; > while(defined($ARGV[$count])) > { >    push(@hash{$abc},$ARGV[$count]); > } > If I guess that correctly, what you want is: push(@{$hash{$abc}},$ARGV[$count]); -- To unsubscribe, e

Re: push coomand on hash variables

2009-11-12 Thread John W. Krahn
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

push coomand on hash variables

2009-11-12 Thread Anant Gupta
.. 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 ..." Help Anant

RE: Hash Variables

2007-11-02 Thread Jenda Krynicky
From: Kevin Viel <[EMAIL PROTECTED]> > > > my %fruit_color = ( apple => "red" > > > , banana => "yellow" > > > ) ; > > > > Sure, you can use it, you can skip it, whichever works better > > for you. > > (I find this style ... erm ... strange, but that's your d

RE: Hash Variables

2007-11-02 Thread Kevin Viel
> > my %fruit_color = ( apple => "red" > > , banana => "yellow" > > ) ; > > Sure, you can use it, you can skip it, whichever works better > for you. > (I find this style ... erm ... strange, but that's your decision.) Thanks for your reply. Could you clari

RE: Hash Variables

2007-10-31 Thread Jenda Krynicky
On 30 Oct 2007 at 9:31, Kevin Viel wrote: > > -Original Message- > > From: Kaushal Shriyan [mailto:[EMAIL PROTECTED] > > Sent: Monday, October 29, 2007 11:25 PM > > To: beginners@perl.org > > Subject: Re: Hash Variables > > > > I am referrin

RE: Hash Variables

2007-10-30 Thread Kevin Viel
> -Original Message- > From: Kaushal Shriyan [mailto:[EMAIL PROTECTED] > Sent: Monday, October 29, 2007 11:25 PM > To: beginners@perl.org > Subject: Re: Hash Variables > > I am referring to perldoc perlintro > my %fruit_color = ("apple", "red&

Re: Hash Variables

2007-10-30 Thread Ron Bergin
On Oct 29, 8:25 pm, [EMAIL PROTECTED] (Kaushal Shriyan) wrote: > Hi > > I am referring to perldoc perlintro > my %fruit_color = ("apple", "red", "banana", "yellow"); > > You can use whitespace and the "=>" operator to lay them out more nicely: > >my %fruit_color = ( >

Re: Hash Variables

2007-10-29 Thread Kaushal Shriyan
Hi I am referring to perldoc perlintro my %fruit_color = ("apple", "red", "banana", "yellow"); You can use whitespace and the "=>" operator to lay them out more nicely: my %fruit_color = ( apple => "red", banana => "yellow", );

Re: Hash Variables

2007-10-29 Thread Matthew Whipple
sivasakthi wrote: > On Mon, 2007-10-29 at 17:06 +0530, Kaushal Shriyan wrote: > > > >> >> >> #!/usr/bin/perl -w >> >> %states = ( "California","Sacramento", "Wisconsin","Madison", "New York", >> "Albany"); >> >> print "Capital of Californi

Re: Hash Variables

2007-10-29 Thread sivasakthi
On Mon, 2007-10-29 at 17:06 +0530, Kaushal Shriyan wrote: > > > #!/usr/bin/perl -w > > %states = ( "California","Sacramento", "Wisconsin","Madison", "New York", > "Albany"); > > print "Capital of California is " . $states{"California"} .

Hash Variables

2007-10-29 Thread Kaushal Shriyan
Hi, I have a sample code #!/usr/bin/perl -w %states = ( "California","Sacramento", "Wisconsin","Madison", "New York", "Albany"); print "Capital of California is " . $states{"California"} . "\n\n"; ###