how many methods for reference creation in perl?
Method 1:
$ref=\"HelloHi";
print $$ref; #HelloHi
Method 2:
$var=5;
$ref="var";
print "$$ref"; #5
Method 3:
@a=(1,2,3);
$ref="a";
print "@$ref"; #1 2 3
Method 4:
%h=(a,b);
$ref="h";
print "$$ref{a}"; #b
Method 5:
sub name
{
print "Hi Lets Crack\n";
}
$ref="name";
&{$ref}; #Hi Lets Crack
Method 6:
$var=5;
$ref=\$var;
print $$ref; #5
Method 7:
@a=(1,2,3);
$ref=\@a;
print "@$ref"; #1 2 3
Method 8:
%h=(a=>b);
$ref=\%h;
print "$$ref{a}\n"; #b
Method 9:
sub name
{
print "Hi Lets Crack\n";
}
$ref=\&name;
&$ref; #Hi Lets Crack
Method 10:
sub name
{
my $a=shift;
print $a "Hi Lets Crack\n";
}
open(FILE,">a.txt");
name(\*FILE);
Method 11:
@a=(1,2,3);
@b=(4,5,6);
@array= name(\@a,\@b);
print @array;
Method 12:
$a="hellohi";
$ref=\substr($a,0,1);
print $$ref; #h
Method 13:
$ref=[1,2,3];
print "@$ref"; #1 2 3
Method 14:
$ref=[qw/1 2 3/];
print "@$ref"; #1 2 3
Method 15:
$ref=[qq/1 2 3/];
print "@$ref"; #1 2 3
Method 16:
$ref={a=>A,
b=>B};
print $$ref{a}; #A
Method 17:
$ref= sub {print "Hello\n"};
&$ref; #Hello
Method 18:
$var=5;
$ref=*var{SCALAR};
print $$ref; #5
Method 19:
$var = 1;
${*var{SCALAR}} = 5;
print $var; #5
Method 20:
sub name
{
print "Hi Lets Crack\n";
}
$ref=*name{CODE};
&$ref; #Hi Lets Crack
kaavannan perl blogspot
$ref=\"HelloHi";
print $$ref; #HelloHi
Method 2:
$var=5;
$ref="var";
print "$$ref"; #5
Method 3:
@a=(1,2,3);
$ref="a";
print "@$ref"; #1 2 3
Method 4:
%h=(a,b);
$ref="h";
print "$$ref{a}"; #b
Method 5:
sub name
{
print "Hi Lets Crack\n";
}
$ref="name";
&{$ref}; #Hi Lets Crack
Method 6:
$var=5;
$ref=\$var;
print $$ref; #5
Method 7:
@a=(1,2,3);
$ref=\@a;
print "@$ref"; #1 2 3
Method 8:
%h=(a=>b);
$ref=\%h;
print "$$ref{a}\n"; #b
Method 9:
sub name
{
print "Hi Lets Crack\n";
}
$ref=\&name;
&$ref; #Hi Lets Crack
Method 10:
sub name
{
my $a=shift;
print $a "Hi Lets Crack\n";
}
open(FILE,">a.txt");
name(\*FILE);
Method 11:
@a=(1,2,3);
@b=(4,5,6);
@array= name(\@a,\@b);
print @array;
Method 12:
$a="hellohi";
$ref=\substr($a,0,1);
print $$ref; #h
Method 13:
$ref=[1,2,3];
print "@$ref"; #1 2 3
Method 14:
$ref=[qw/1 2 3/];
print "@$ref"; #1 2 3
Method 15:
$ref=[qq/1 2 3/];
print "@$ref"; #1 2 3
Method 16:
$ref={a=>A,
b=>B};
print $$ref{a}; #A
Method 17:
$ref= sub {print "Hello\n"};
&$ref; #Hello
Method 18:
$var=5;
$ref=*var{SCALAR};
print $$ref; #5
Method 19:
$var = 1;
${*var{SCALAR}} = 5;
print $var; #5
Method 20:
sub name
{
print "Hi Lets Crack\n";
}
$ref=*name{CODE};
&$ref; #Hi Lets Crack
kaavannan perl blogspot
Labels: dereferencing in perl, kaavannan perl blogspot, perl array reference, perl hash, perl reference, perl reference to hash, perl reference to subroutine
0 Comments:
Post a Comment
Note: only a member of this blog may post a comment.
<< Home