I think that your looking at this from the wrong angle.

I would say the my, our, package and sub all declare something. They declare a name.

The fact that in some cases, that name will refer to a piece of storage that may already exist our, or a new piece of storage that will be created my, or to a potentially pre-existing, namespace in which other names can be grouped package, or a name of a piece of code, that will exist within current, potentially implicitly named, namespace sub, could be considered a side-effect of the declaration to the compiler that I wish to use a particular name at the current level of scope.

This is further reenforced on those occasions when my doesn't cause a new piece of memory to be allocate. Eg.

for my $key ( keys %hash ) {...} while( my $line = <FILE> ) {...}

In both these cases, my isn't creating anything. It is declaring a name that is used to refer to a pre-existing piece of storage for the duration of a level of scope.

In all cases, the four keywords declare names that the programmer wishes to use for some entity. That sometimes that entity may be a pre-existing one and other cases it will be created is (almost) incidental.

The joker in the pack of course is local, which says I wish to use a pre-existing name to refer to a new piece of storage.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller



In reply to Re: On Declaration by BrowserUk
in thread On Declaration by demerphq

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.