go ahead... be a heretic | |
PerlMonks |
Re: How to access a variable inside subroutine?by haukex (Archbishop) |
on Sep 05, 2020 at 19:20 UTC ( [id://11121382]=note: print w/replies, xml ) | Need Help?? |
jeffenstein has said why it doesn't work, I'm wondering what you're trying to achieve? Depending on that, there are several possible solutions, one would be to have the subroutine return the value of $add so you can access it outside the subroutine. Another, though less common in Perl, would be to have the subroutine modify its arguments. And although I hesitate to mention it, you could also use a global variable.
In Section
Seekers of Perl Wisdom
|
|