Front page | perl.beginners |
Postings from November 2009
Re: push coomand on hash variables
Thread Previous
|
Thread Next
From:
Erez Schatz
Date:
November 13, 2009 02:34
Subject:
Re: push coomand on hash variables
Message ID:
e7f13a450911130234g564acd4eo152bf972ad17b88e@mail.gmail.com
2009/11/13 Anant Gupta <anantguptadbl@gmail.com>:
> 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.
It is. A hash can be defined as %hash = ( 'abc', 'def', 'ghi', 'jkl',
'mnp', 'pqr'); %hash = ( abc => 'def', ghi => 'jkl', mnp => 'pqr'); or
$hash = { 'abc' => 'def', 'ghi' => 'jkl', 'mnp' => 'pqr'};
The difference is that the => operator (aka "fat comma") allows you to
write the "key" value without quote marks, and the $hash ={...
definition is creating an anonymous hash and assigning it to $hash,
which is a hashref.
> Is it so? Can we directly define reference variables like this?
Yes, Perl allows you to do that with every data type, same with
$arrayref = [1, 2, ['a', 'b', 'c']]; read perlref (perdoc perlref from
your command line/shell, or http://perldoc.perl.org/perlref.html from
your browser) for more information about references in perl.
--
Erez
"The government forgets that George Orwell's 1984 was a warning, and
not a blueprint"
http://www.nonviolent-conflict.org/ -- http://www.whyweprotest.org/
Thread Previous
|
Thread Next