Says arturo:
> use foreach my $element (@array) {... } ... $element will be set to
> the value of the current element of the array on each step through
> the array, and modifying it won't change your array.
Wrong. (Good thing I caught that for you, because you say that's one of your favorite uses, and it's probably just dumb luck that you haven't gotten into big trouble by modifying the loop variable when you thought you were safe from modifying the array.)

> local $foo ... determines that in the
> current block and any code called by the current
> block, $foo refers to a different variable.

Also wrong. It's the same variable. Nor does local affect the interpretation of $foo in called subroutines.

local changes the value of the variable. It saves the old value, and arranges for the old value to be automatically restored later on.

Called subroutines see the new value of $foo, just as if you had assigned to it.

Hope this helps.


In reply to Re: (proposed)Scoping tutorial by Dominus
in thread (proposed)Scoping tutorial by arturo

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.