Fwd: Re: variable losing it's value

2001-06-19 Thread Bob Mangold
--- Bob Mangold <[EMAIL PROTECTED]> wrote: > Date: Tue, 19 Jun 2001 19:40:51 -0700 (PDT) > From: Bob Mangold <[EMAIL PROTECTED]> > Reply-to: [EMAIL PROTECTED] > Subject: Re: variable losing it's value > To: Michael Fowler <[EMAIL PROTECTED]> > > B

Re: variable losing it's value

2001-06-19 Thread Rogério Brito
On Jun 19 2001, Bob Mangold wrote: > my ($line) = "hello"; > foreach $line (<>){ > . whatever > } > print $line; This code snippet will print "hello", since the foreach loop gives its iterator variable an implicit declaration with "local", AFAIK. []s, Ro

Re: variable losing it's value

2001-06-19 Thread Michael Fowler
On Tue, Jun 19, 2001 at 09:39:13PM -0400, Eric Beaudoin wrote: > At 16:39 2001.06.19, Jeff 'japhy' Pinyan wrote: > >This is because the looping variable is implicitly localized to the loop > >itself. This is not a bug. > > Has this always been the case? I was under the impression that the syntax

Re: variable losing it's value

2001-06-19 Thread Eric Beaudoin
At 16:39 2001.06.19, Jeff 'japhy' Pinyan wrote: >On Jun 19, Bob Mangold said: > >>I may have a bug somewhere in my code, but I can't find it. Before I >>look again though please answer this for me. > >>my ($line) = "hello"; >>foreach $line (<>){ >> . whatever >>} >>print $line; >> >>Should

Re: variable losing it's value

2001-06-19 Thread Michael Fowler
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 i

Re: variable losing it's value

2001-06-19 Thread Chas Owens
The standard idiom is: foreach my $item (@items) { } On 19 Jun 2001 14:41:40 -0700, Bob Mangold wrote: > Thanks, that's what I thought was happening, but now I have another question. > If I 'use strict' (and who doesn't), I am forced to declare $line before the > foreach loop, except I can't jus

Re: variable losing it's value

2001-06-19 Thread Bob Mangold
Thanks, that's what I thought was happening, but now I have another question. If I 'use strict' (and who doesn't), I am forced to declare $line before the foreach loop, except I can't just type 'foreach my($line) (<>)'. I have to type it on a preceeding line. If this is the case then why does perl

Re: variable losing it's value

2001-06-19 Thread Jeff 'japhy' Pinyan
On Jun 19, Bob Mangold said: >I may have a bug somewhere in my code, but I can't find it. Before I >look again though please answer this for me. >my ($line) = "hello"; >foreach $line (<>){ > . whatever >} >print $line; > >Should it print the last line in <> or 'hello'? I don't think th

RE: variable losing it's value

2001-06-19 Thread Wagner-David
You are overlaying $line each time you read a line from <>. SO it will be the last line from whatever files if any were passed. Wags ;) -Original Message- From: Bob Mangold [mailto:[EMAIL PROTECTED]] Sent: Tuesday, June 19, 2001 13:25 To: [EMAIL PROTECTED] Subject: variable losin

Re: variable losing it's value

2001-06-19 Thread perl
When you do : foreach $line (<>){ that will print the last line in <> rename $line in the foreach statement to something different, RYan On Tue, 19 Jun 2001, Bob Mangold wrote: > I may have a bug somewhere in my code, but I can't find it. Before I look again > though please answer this for

variable losing it's value

2001-06-19 Thread Bob Mangold
I may have a bug somewhere in my code, but I can't find it. Before I look again though please answer this for me. If I execute: my ($line) = "hello"; foreach $line (<>){ . whatever } print $line; Should it print the last line in <> or 'hello'? -Bob