Re: Strange interaction of "my"-variables with initialization

2008-01-14 Thread Dr.Ruud
Peter Daum schreef: > my $x = undef; > foreach ( qw(a b c) ) { > my $t = $x if $x; > warn( "\$t == ", $t||'undef', "\n" ); > $t = $_; > } > > $t would be initialized with the value of $x if that was true; > otherwise (at least that's what I would expect) $t should be > undefined, > so

Re: Strange interaction of "my"-variables with initialization

2008-01-13 Thread John W. Krahn
Chas. Owens wrote: On Jan 13, 2008 1:20 PM, John W. Krahn <[EMAIL PROTECTED]> wrote: snip Statements don't define scope, braces and files define scope. snip so why should you be able to use it because it has been changed to this my $t = $x if $x; print "$t\n"; You can use it because it is i

Re: Strange interaction of "my"-variables with initialization

2008-01-13 Thread Chas. Owens
On Jan 13, 2008 1:20 PM, John W. Krahn <[EMAIL PROTECTED]> wrote: snip > Statements don't define scope, braces and files define scope. snip > > so why should you be able to use it because it has been changed to this > > > > my $t = $x if $x; > > print "$t\n"; > > You can use it because it is in th

Re: Strange interaction of "my"-variables with initialization

2008-01-13 Thread John W. Krahn
Chas. Owens wrote: On Jan 13, 2008 6:22 AM, Peter Daum <[EMAIL PROTECTED]> wrote: snip my $t =$x if $x; snip $t would be initialized with the value of $x if that was true; otherwise (at least that's what I would expect) $t should be undefined, so the result would be as before. The real out

Re: Strange interaction of "my"-variables with initialization

2008-01-13 Thread Chas. Owens
On Jan 13, 2008 6:22 AM, Peter Daum <[EMAIL PROTECTED]> wrote: snip > my $t =$x if $x; snip > $t would be initialized with the value of $x if that was true; > otherwise (at least that's what I would expect) $t should be undefined, > so the result would be as before. The real outcome, however, i

Re: Strange interaction of "my"-variables with initialization

2008-01-13 Thread John W. Krahn
Peter Daum wrote: Hi, Hello, I just got bitten by a very simple issue, where Perl behaves totally different from what I had expected; According to the documentation, lexical variables are visible only after the line they have been declared in; they may be initialized; otherwise their value i

Strange interaction of "my"-variables with initialization

2008-01-13 Thread Peter Daum
Hi, I just got bitten by a very simple issue, where Perl behaves totally different from what I had expected; According to the documentation, lexical variables are visible only after the line they have been declared in; they may be initialized; otherwise their value is undefined, so the following

Re: Lifetime of my() variables

2006-02-28 Thread Jeff Pang
Tom is very right.It's a closure indeed.:-) -Original Message- >From: Tom Phoenix <[EMAIL PROTECTED]> >Sent: Mar 1, 2006 7:20 AM >To: Timothy Johnson <[EMAIL PROTECTED]> >Cc: beginners@perl.org >Subject: Lifetime of my() variables > >On 2/28/06, Tim

RE: Lifetime of my() variables

2006-02-28 Thread Timothy Johnson
An important distinction. Thanks. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Tom Phoenix Sent: Tuesday, February 28, 2006 3:21 PM To: Timothy Johnson Cc: beginners@perl.org Subject: Lifetime of my() variables On 2/28/06, Timothy Johnson <[EM

Lifetime of my() variables

2006-02-28 Thread Tom Phoenix
On 2/28/06, Timothy Johnson <[EMAIL PROTECTED]> wrote: > If you declare a variable with my(), it only exists within the current > scope Not to be too picky, but it's more accurate to say that it's the variable's *name* that's restricted to the given scope. The variable itself exists so long as th

RE: 'my' variables

2002-05-14 Thread Hanson, Robert
t: Tuesday, May 14, 2002 5:08 PM To: '[EMAIL PROTECTED]' Cc: HENRY,MARK (HP-Roseville,ex1) Subject: Re: 'my' variables Jonathan, Thanks for the reply.. >use strict; >Always, always, declare your variables with my.[1] What do you mean by "function" variabl

Re: 'my' variables

2002-05-14 Thread HENRY,MARK (HP-Roseville,ex1)
Jonathan, Thanks for the reply.. >use strict; >Always, always, declare your variables with my.[1] What do you mean by "function" variables? Ok, I understand you mean use 'my' to declare containers for incoming arg variables - what about variables used just within the function - ought they be

Re: 'my' variables

2002-05-14 Thread Jonathan E. Paton
> Assuming I used unique variable names throughout my entire program, then is > if correct to say I don't need to declare function variables with 'my'? use strict; Always, always, declare your variables with my.[1] What do you mean by "function" variables? If you are suggesting "pass by global

'my' variables

2002-05-14 Thread HENRY,MARK (HP-Roseville,ex1)
Hi All, Assuming I used unique variable names throughout my entire program, then is if correct to say I don't need to declare function variables with 'my'? I'm trying to figure out what advantage they give, apart from avoiding name collision (and some speed?). On the same note, is it generally

Re: my variables

2001-11-08 Thread Jeff 'japhy' Pinyan
On Nov 8, Arul, Rex said: >use strict; >my $a= 2; >print "a val is $a\n"; >my $a= 10; >print "a val is $a\n"; > >My question is. How can I put a 'seat-belt' as to tag this kind of >inadvertent behavior as unacceptable? > >When I use, 'use warnings' pragma, it warns me. Is there anything

my variables

2001-11-08 Thread Arul, Rex
In Javascript you cannot declare same variable twice within the same scope. However, I noticed that I can do that in Perl. use strict; my $a= 2; print "a val is $a\n"; my $a= 10; print "a val is $a\n"; My question is. How can I put a 'seat-belt' as to tag this kind of inadvertent behavi