[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] $_ global?




It was my understanding that most variables are global, including '$_' .  I don't have the new camel book yet; perhaps this has changed in perl 5.

Here is some code that seems to show '$_' as a local variable:
------------------------------
$_ = "Am I global?";
print "$_\n";
@marbles = ('red','orange','yellow','green','blue','indigo','violet');
foreach (@marbles) {print "$_\n";}
print "$_\n";
------------------------------

And here are the results:
------------------------------
Am I global?
red
orange
yellow
green
blue
indigo
violet
Am I global?
------------------------------

Why is '$_' acting as a local variable? 
I want it to be global, so how to make it work?


Thanks everyone,

Terry Lynch