We don't bite newbies here... much | |
PerlMonks |
Re: How to access a variable inside subroutine?by jcb (Parson) |
on Sep 05, 2020 at 19:44 UTC ( [id://11121385]=note: print w/replies, xml ) | Need Help?? |
This should do what you seem to be trying to do: (untested)
This uses our to establish lexical aliases to a global variable "add" briefly as needed. For a small program, or within a module, this can be a useful technique, but please be careful not make gratuitous uses of global variables across larger programs. If you need more than one counter, objects are a better approach: (also untested)
Used like so:
Note however, that $counter->count(0) adds 1! Think about why this is so.
In Section
Seekers of Perl Wisdom
|
|