in reply to Re: Global variable vs passing variable from sub to sub
in thread Global variable vs passing variable from sub to sub
I don't understand the last line of:This is incredibly simple perl code. It simple accesses a hash and compares a scalar to another scalar. If you don't understand this perhaps you should read some tutorials?sub account_over_limit { my ($account, $balance) = @_; return exists $LIMITED_ACCOUNTS{$account} && $balance > $LIMIT; }
And I don't understand the point of:sub; is a compile time statement, so the BEGIN block forces the assignment to happen at compile time also. Also it helps lexically scope $var so nothing else can touch it. Similar to inside out objects.BEGIN { my $var; sub set_var { $var = shift; } sub var { $var; } }
'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.Let me put it this way and see if it makes more sense. I have a 11,000 line program. It has 10 globals at the top. Because they're global, this means that *any* single one of those 11,000 lines can modify that global value. Therefor, when your global has the *wrong* value, you have problems finding it, because you must examine 11,000 lines of code.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Global variable vs passing variable from sub to sub
by kiat (Vicar) on Sep 14, 2004 at 11:16 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |