[ACCEPTED]-What does {} mean in perl?-perl
Accepted answer
{} creates a reference to an empty anonymous 1 hash. Read more here.
Example code:
use Data::Dumper;
my $a = {};
print "a is " . Dumper( $a );
my %b = ();
print "b is " . Dumper( \%b );
Outputs:
a is $VAR1 = {};
b is $VAR1 = {};
{}
, in this context, is the anonymous hash 5 constructor.
It creates a new hash, assigns 4 the result of the expression inside the 3 curlies to the hash, then returns a reference 2 to that hash.
In other words,
{ EXPR }
is roughly equivalent 1 to
do { my %hash = ( EXPR ); \%hash }
(EXPR
can be null, nothing.)
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.