http://www.perlmonks.org?node_id=390767


in reply to Global variable vs passing variable from sub to sub

Yeah, that's right. I'm back, and I have something to say. This is really a reply to people who've given code examples in this thread.

I don't understand the last line of:

sub account_over_limit { my ($account, $balance) = @_; return exists $LIMITED_ACCOUNTS{$account} && $balance > $LIMIT; }
And I don't understand the point of:

BEGIN { my $var; sub set_var { $var = shift; } sub var { $var; } }

I've had numerous problems trying to determine where a global was changed, and I have a feeling there's a good anti-global argument around here somewhere, but I can't find it. When a script is doing alot of calculating and outputting just the end result, I don't think it matters how localized things are. You still won't know what affected the output.

Another, barely related thing--I'm just about done with a GNU tar GUI for Windows, and I'm finding good uses for goto all over the place.

Anyway, please make your code examples as simple as possible and explain them properly.