Wakan Tanka
Wakan Tanka

Reputation: 8052

perl - calling to ref did not return anything

can somebody explain why calling ref did not return anything ?

[pista@HP-PC ~]$ perl -wlae '$var=1; print ref($var)'

[pista@HP-PC ~]$ perl -wlae '@var=1; print ref(@var)'

[pista@HP-PC ~]$ perl -v

This is perl 5, version 14, subversion 3 (v5.14.3) built for x86_64-linux-thread-multi

Copyright 1987-2012, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

 [pista@HP-PC ~]$ uname -a
Linux HP-PC 3.6.11-1.fc16.x86_64 #1 SMP Mon Dec 17 21:29:15 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

What I am doing wrong ?

Upvotes: 3

Views: 2673

Answers (2)

robertklep
robertklep

Reputation: 203419

@var isn't a ref, it's an array. Try ref(\@var).

Upvotes: 4

TLP
TLP

Reputation: 67900

From perldoc -f ref:

ref EXPR
ref     Returns a non-empty string if EXPR is a reference, the empty
        string otherwise. 

Your values are a scalar and an array, which are not references, hence ref returns the empty string. If you were to do:

print ref \$var;

You would get the output: SCALAR

Upvotes: 9

Related Questions