On Tue, Jun 19, 2001 at 02:41:40PM -0700, Bob Mangold wrote:
[snip]
> except I can't just type 'foreach my($line) (<>)'.

That's because your syntax is wrong.  It should be:

    foreach my $line (<>) {

Assuming you actually want to use foreach for such a thing.  What you really
should be using is:

    while (defined(my $line = <>)) {


> I have to type it on a preceeding line. If this is the case then
> why does perl localize it anyway. If i'm declaring it before that loop
> shouldn't its scope carry through the loop?

I believe the reason for this behaviour lies in the foreach loop's aliasing
feature.  The iterator variable ($line) is an alias for the actual value in
the list; modifications to the iterator modify the original list element (if
it's modifiable).  To support this feature the iterator variable must
actually -be- the list element.  This feature is more useful than the
ability to keep the last value of the list.


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

Reply via email to