[ale] perl question

Calvin Harrigan charriglists at bellsouth.net
Mon Jan 16 15:59:05 EST 2012


On 1/16/2012 2:45 PM, Geoffrey Myers wrote:
> Okay, so why is it that $foo is empty inside the sub bar() ??

Because it was never initialized.
set $foo to some value before the loop and be amazed by the weakness of 
perl.  I kid of course.  Localizing the variable means (I think) that 
it's the loop variable is taken from the stack even if there is a 
variable with the name.  So the value of the variable  (null in this 
case) name perl stays untouched. Only the foreach does this as far as I 
know.

<snip>

 > 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.

I know the loop seems to work, but the value of the variable(s) are 
wrong because of the foreach localization issue I mentioned before.



More information about the Ale mailing list