2009/11/13 Anant Gupta <anantgupta...@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/

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to