Thank you for this example, the following one makes it even more obvious!
use strict; use warnings; sub pr { my $ref= ref($_[0]) ? $_[0] : \$_[0]; print $ref,"\t"; # print ref of para } check(qw/ Scalar 1 /); check(qw/ Array [1,2] /); check(qw/ Hash {1,2} /); sub check { my ($_title_,$type) = @_; my $_call_ ="pr $type;"; my $code= <<"__EOC"; for (1..3) { $_call_ print "\\n\\t"; #UPDATE for (1..3) { $_call_ } print "\\n"; } __EOC print "\n--- $_title_ \n"; print $code; eval $code; }
OUTPUT
--- Scalar for (1..3) { pr 1; print "\n\t"; #UPDATE for (1..3) { pr 1; } print "\n"; } SCALAR(0x818ad04) SCALAR(0x818acec) SCALAR(0x818acf8) SCALAR(0x818ac +ec) SCALAR(0x818acf8) SCALAR(0x818ad10) SCALAR(0x818acec) SCALAR(0x818ad +10) SCALAR(0x818acec) SCALAR(0x818ad04) SCALAR(0x818ad10) SCALAR(0x818ad +04) --- Array for (1..3) { pr [1,2]; print "\n\t"; #UPDATE for (1..3) { pr [1,2]; } print "\n"; } ARRAY(0x818acf8) ARRAY(0x818acd4) ARRAY(0x818acd4) ARRAY(0x818acd +4) ARRAY(0x818acd4) <----- FAILS ARRAY(0x818acf8) ARRAY(0x818acf8) ARRAY(0x818acf +8) ARRAY(0x818acf8) ARRAY(0x818acd4) ARRAY(0x818acd4) ARRAY(0x818acd +4)
Thanks for teh discussion!!!

Cheers Rolf


In reply to Re^6: Reference of constants and literals by LanX
in thread Reference of constants and literals by LanX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.