Push is a CORE:: subroutine which you can override, please check perlsub

> Printing \$_[0] would print a reference to a reference to an array, not a reference to a reference.

well the constant gets always at runtime a reallocated space, while the arrayref doesn't!!!

here a code that makes it hopefully clearer.

UPDATE: no it doesn't, passing a ref to a literal scalar works as wanted!!!

use strict; use warnings; sub pr { print \$_[0]," : ",$_[0],"\t"; # print ref:value of para } check(qw/ Scalar 1 /); check(qw/ Scalarref \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"; for (1..3) { $_call_ } print "\\n"; } __EOC print "\n--- $_title_ \n"; print $code; eval $code; } __END__ --- Scalar for (1..3) { pr 1; print "\n\t"; for (1..3) { pr 1; } print "\n"; } SCALAR(0x81953b0) : 1 SCALAR(0x8190778) : 1 SCALAR(0x8190754) : 1 SCALAR(0x8190778 +) : 1 SCALAR(0x8190754) : 1 SCALAR(0x819076c) : 1 SCALAR(0x8190778) : 1 SCALAR(0x819076c +) : 1 SCALAR(0x8190778) : 1 SCALAR(0x81953b0) : 1 SCALAR(0x819076c) : 1 SCALAR(0x81953b0 +) : 1 --- Scalarref for (1..3) { pr \1; print "\n\t"; for (1..3) { pr \1; } print "\n"; } REF(0x8190754) : SCALAR(0x81953ec) REF(0x8190760) : SCALAR(0x8195428) REF(0x819073c) : SCALAR(0x81 +95428) REF(0x8190760) : SCALAR(0x8195428) REF(0x819073c) : SCALAR(0x81953ec) REF(0x81953b0) : SCALAR(0x8195428) REF(0x8190760) : SCALAR(0x81 +95428) REF(0x81953b0) : SCALAR(0x8195428) REF(0x8190760) : SCALAR(0x81953ec) REF(0x8190754) : SCALAR(0x8195428) REF(0x81953b0) : SCALAR(0x81 +95428) REF(0x8190754) : SCALAR(0x8195428) --- Array for (1..3) { pr [1,2]; print "\n\t"; for (1..3) { pr [1,2]; } print "\n"; } REF(0x8190754) : ARRAY(0x81953c8) REF(0x8190724) : ARRAY(0x819073c) REF(0x8190724) : ARRAY(0x8190 +73c) REF(0x8190724) : ARRAY(0x819073c) REF(0x8190754) : ARRAY(0x819073c) REF(0x8190724) : ARRAY(0x81953c8) REF(0x8190724) : ARRAY(0x8195 +3c8) REF(0x8190724) : ARRAY(0x81953c8) REF(0x8190754) : ARRAY(0x81953c8) REF(0x8190724) : ARRAY(0x819073c) REF(0x8190724) : ARRAY(0x8190 +73c) REF(0x8190724) : ARRAY(0x819073c) --- Hash for (1..3) { pr {1,2}; print "\n\t"; for (1..3) { pr {1,2}; } print "\n"; } REF(0x81953c8) : HASH(0x8154708) REF(0x8190748) : HASH(0x81953c8) REF(0x8190748) : HASH(0x81953c +8) REF(0x8190748) : HASH(0x81953c8) REF(0x8154708) : HASH(0x81953c8) REF(0x8190748) : HASH(0x8154708) REF(0x8190748) : HASH(0x815470 +8) REF(0x8190748) : HASH(0x8154708) REF(0x81953c8) : HASH(0x8154708) REF(0x8190748) : HASH(0x81953c8) REF(0x8190748) : HASH(0x81953c +8) REF(0x8190748) : HASH(0x81953c8)

Cheers Rolf


In reply to Re^4: 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.