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

This is off topic. I wanted to ignore the push example to avoid going off topic.

push is a named operator, which Perl calls "built-in function" or just "function". There are number of differences between subroutines and functions.

As for CORE::push, it's very special. It's both a subroutine and a function depending how it's used. \&CORE::push returns a code ref, so it acts as a subroutine. But CORE::push(...) results in a push operator, not a subroutine call.

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

You haven't shown that the array ref doesn't get reallocated. To do so, you'd have to show that the array doesn't happen to get reallocated at the same memory address. All you have is a theory. One that's provably false.

my $code= <<"__EOC"; my \@x; <-- added for (1..3) { $_call_ print "\\n\\t"; for (1..3) { $_call_ push \@x, 'x'; <-- added } print "\\n"; } __EOC
--- Array my @x; for (1..3) { pr [1,2]; print "\n\t"; #UPDATE for (1..3) { pr [1,2]; push @x, 'x'; } print "\n"; } REF(0x18538d8) REF(0x18538c0) REF(0x185389c) REF(0x1853950) REF(0x185389c) REF(0x1853914) REF(0x1853920) REF(0x18538a8) REF(0x1853920) REF(0x1853884) REF(0x1853890) REF(0x185386c)

And that brings me back to my earlier answer. The behaviour is not intentional. It's a fluke and relying on it is dangerous.


In reply to Re^5: Reference of constants and literals by ikegami
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.