I was wondering about the possible return values of the
ref function until I came across the list in
ref.
I also verified that the 11 return values are printed using the following code.
format =
.
sub fun
{
print "\nThis is fun";
}
$packRef={};
bless $packRef,"NONSENSE";
$scalarRef=\$_; #1
$arrRef=\@ARGV; #2
$hashRef=\%ENV; #3
$codeRef=\&fun; #4
$refRef=\$scalarRef; #5
$globRef=\*STDIN; #6
$lvalueRef=\ substr ("learning perl",0,4); #7
$regexpRef= qr/something/; #8
$formatRef= *STDOUT{FORMAT};#9
$ioRef= *STDOUT{IO}; #10
$vstringRef= \v5.10.10; #11
print "\n1. scalarref is ". ref($scalarRef);
print "\n2. arrRef is ". ref($arrRef);
print "\n3. hashRef is ". ref($hashRef);
print "\n4. codeRef is ". ref($codeRef);
print "\n5. refRef is ". ref($refRef);
print "\n6. globRef is ". ref($globRef);
print "\n7. lvalueRef is ". ref($lvalueRef);
print "\n8. regexpRef is ". ref($regexpRef);
print "\n9. formatRef is ". ref($formatRef);
print "\n10. ioRef is ". ref($ioRef);
print "\n11. vstringRef is ". ref($vstringRef); #prints SCALAR
print "\n12. packRef is ". ref($packRef);
However, I could not get the
vstringRef to print VSTRING. Any clues why #11 above shows SCALAR?
Secondly, I have always come across the statement
Perl has three basic types : scalars, arrays, hashes
However, I have not found a definitive for this in perldocs (I was trying to find a list like there was one for 11 possible return types of ref function).
Could anyone elaborate why the return values of ref can't be called as data types in Perl?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.