in reply to Re: Difference my and local
in thread Difference my and local
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.
which outputs something like: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"; }
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"
|
|---|