Saturday, 16 November 2019

Anonymous variables in Perl?


A variable which is not having name is called anonymous variables.it returns a reference to a new variable.

Method 1:


$newvariable = [1,2,3];
print $$newvariable[0];

or

print $newvariable->[0];

or

print @$newvariable




Method 2:

$newvariable = {name => perl,
                code=> 1,}

print $$newvariable{name}

or

print $newvariable->{name}

Method 3:

$newvariable=sub{print "hello perl\n"};

&$newvariable;

or

$newvariable=sub{print shift};

&$newvariable("hello perl\n");

or

$newvariable->("hello perl\n");

Labels: , ,

0 Comments:

Post a Comment

Note: only a member of this blog may post a comment.

<< Home