[ale] perl question

Brian Mathis brian.mathis+ale at betteradmin.com
Tue Jan 17 11:44:05 EST 2012


On Tue, Jan 17, 2012 at 11:22 AM, Derek Atkins <warlord at mit.edu> wrote:
> Geoffrey Myers <lists at serioustechnology.com> writes:
>
>> Oh the loop works as defined, it's just that the value is not passed to
>> the sub bar()  My expectation was that since the call to bar() was
>> inside the loop, that $foo would be accessible within the sub.
>
> Alas, it doesn't work that way.  PERL doesn't scope variables that way.
> You would need to define a global and assign it, or you would need to
> pass it as a variable to the sub.
>
> -derek


It doesn't, and shouldn't, work that way in /any/ programming
language.  The problem is definitely that the variables are never
passed to the sub, and trying to do it through bash-style globals is
very, very bad form (bash is not a programming language).

The first thing you should be doing in all Perl programs is "use
strict;" before anything else.  That would have caught this error
right away.


❧ Brian Mathis



More information about the Ale mailing list