Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re^3: why is $1 cleared at end of an inline sub?

by LanX (Sage)
on Sep 17, 2021 at 23:08 UTC ( #11136854=note: print w/replies, xml ) Need Help??

in reply to Re^2: why is $1 cleared at end of an inline sub?
in thread why is $1 cleared at end of an inline sub?

maybe haukex understood your problem and you need to get acquainted with dynamic-scoping ... which is the only possible way to have limited control over global variables.

NB: our package-vars and special vars like $1 are global. They are accessible everywhere at run-time and prone to "sabotage".

Static aka lexical scoping is a totally different beast for my vars at compile-time.

Try to debug a global variable which suddenly changes after you called a sub from a foreign module you just upgraded.

And special vars are not protected by namespaces, they are all in main:: !

That's why they are automatically localized in subs.

Dynamic scoping was already a given in Perl4, which had no such thing like my or lexical scoping.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11136854]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2021-10-21 10:32 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (83 votes). Check out past polls.