What is the difference between my and local in Perl?

前端 未结 14 1651
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-01 03:13

I am seeing both of them used in this script I am trying to debug and the literature is just not clear. Can someone demystify this for me?

14条回答
  •  无人及你
    2020-12-01 03:49

    Well Google really works for you on this one: http://www.perlmonks.org/?node_id=94007

    From the link:

    Quick summary: 'my' creates a new variable, 'local' temporarily amends the value of a variable.

    ie, 'local' temporarily changes the value of the variable, but only within the scope it exists in.

    Generally use my, it's faster and doesn't do anything kind of weird.

提交回复
热议问题