Well, as a rule of thumb: use my everywhere, and only if perl complains about, think about using local (e.g. with build in perl variables)

With local, you can also localize parts of datastructures, e.g.

use warnings; use strict; use vars qw(@array); @array = 1..20; print "BEFORE: @array\n"; &TestSub(); print "AFTER: @array\n"; sub TestSub { local @array[4..10]; @array[4..11] = 104..111; print "INSIDE: @array\n"; }
which outputs something like:
BEFORE: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 INSIDE: 1 2 3 4 104 105 106 107 108 109 110 111 13 14 15 16 17 18 19 2 +0 AFTER: 1 2 3 4 5 6 7 8 9 10 11 111 13 14 15 16 17 18 19 20

beware that 111 is not "localized" and so the change is global.

Best regards,
perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"


In reply to Re^2: Difference my and local by strat
in thread Difference my and local by Anonymous Monk

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.