Re: why $000 is a valid variable name?

2004-11-18 Thread Ing. Branislav Gerzo
Zeng Nan [ZN], on Thursday, November 18, 2004 at 13:43 (+0800) wrote
these comments:

ZN> As said in "Learning Perl", a perl identifier is "a letter or
ZN> underscore, and then possibly more letters, or digits, or underscores".
ZN> Because of this, $123 is an invalid name, but why $000 or $00 works?

I think it has something to do with regular expressions, you use
$[1-9] for back references, and $0 is unused (?)

-- 

 ...m8s, cu l8r, Brano.

["That's your problem, not mine.  Doctor out."-Doc Zimmerman]



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: why $000 is a valid variable name?

2004-11-18 Thread Wiggins d Anconia
> Zeng Nan [ZN], on Thursday, November 18, 2004 at 13:43 (+0800) wrote
> these comments:
> 
> ZN> As said in "Learning Perl", a perl identifier is "a letter or
> ZN> underscore, and then possibly more letters, or digits, or
underscores".
> ZN> Because of this, $123 is an invalid name, but why $000 or $00
works?
> 
> I think it has something to do with regular expressions, you use
> $[1-9] for back references, and $0 is unused (?)
> 
>

>From perldoc perlvar:
"$0 Contains the name of the program being executed."

I suspect that the variable is actually $0 and the rest of the numbers
are taken as a string of zeros, but that probably depends on context and
whether or not you have strict/warnings enabled.  I know this came up
before, because Vim syntax highlighting was doing the wrong thing (patch
was submitted, but not by me), check the archives sorry I can't provide
a good search string, it was a while ago.

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: why $000 is a valid variable name?

2004-11-18 Thread Larsen, Errin M HMMA/IT

> > Zeng Nan [ZN], on Thursday, November 18, 2004 at 13:43 
> (+0800) wrote 
> > these comments:
> > 
> > ZN> As said in "Learning Perl", a perl identifier is "a letter or 
> > ZN> underscore, and then possibly more letters, or digits, or
> underscores".
> > ZN> Because of this, $123 is an invalid name, but why $000 
> or $00
> works?


  I tried the following code:
#!/usr/bin/perl

use warnings;
use strict;

my $00 = "Two Zeros";
my $000 = "Three Zeros";
my $ = "Four Zeros";

print "\$0= $0\n";
print "\$00   = $00\n";
print "\$000  = $000\n";
print "\$ = $\n";


  And I got the following output:
Can't use global $00 in "my" at ./zerotest line 6, near "my $00 "
Can't use global $000 in "my" at ./zerotest line 7, near "my $000 "
Can't use global $ in "my" at ./zerotest line 8, near "my $ "
Execution of ./zerotest aborted due to compilation errors.


  BUT ... When I removed the "warnings" and "strict", and stopped using
"my", it works:

#!/usr/bin/perl

$00 = "Two Zeros";
$000 = "Three Zeros";
$ = "Four Zeros";

print "\$0= $0\n";
print "\$00   = $00\n";
print "\$000  = $000\n";
print "\$ = $\n";


  The above code produced the following output:
$0= ./zerotest
$00   = Two Zeros
$000  = Three Zeros
$ = Four Zeros

So ... Um, weird!

--Errin

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: why $000 is a valid variable name?

2004-11-18 Thread Chris Devers
On Thu, 18 Nov 2004, Larsen, Errin M HMMA/IT wrote:

>   BUT ... When I removed the "warnings" and "strict", and stopped 
> using "my", it works:

Which is all the more reason to always use warnings & strict! :-)
 
 

-- 
Chris Devers

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: why $000 is a valid variable name?

2004-11-18 Thread Chasecreek Systemhouse
On Thu, 18 Nov 2004 09:28:07 -0500 (EST), Chris Devers
<[EMAIL PROTECTED]> wrote:
> On Thu, 18 Nov 2004, Larsen, Errin M HMMA/IT wrote:
> 
> >   BUT ... When I removed the "warnings" and "strict", and stopped
> > using "my", it works:
> 
> Which is all the more reason to always use warnings & strict! :-)


!!! 

I refuse to be "locked-in" by something as un-useful as correct programming  =)

(Im joking -- but who can tell these days.  :)

-- 
WC -Sx- Jones
http://insecurity.org/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: why $000 is a valid variable name?

2004-11-18 Thread Jose Alves de Castro
On Thu, 2004-11-18 at 14:27, Larsen, Errin M HMMA/IT wrote:
>   BUT ... When I removed the "warnings" and "strict", and stopped using
> "my", it works:

replacing "my" with "our" does the trick too.


-- 
José Alves de Castro <[EMAIL PROTECTED]>
  http://jose-castro.org/


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: why $000 is a valid variable name?

2004-11-18 Thread Zeng Nan
On Thu, Nov 18, 2004 at 02:15:45PM +0100, Ing. Branislav Gerzo wrote:
> Zeng Nan [ZN], on Thursday, November 18, 2004 at 13:43 (+0800) wrote
> these comments:
> 
> ZN> As said in "Learning Perl", a perl identifier is "a letter or
> ZN> underscore, and then possibly more letters, or digits, or underscores".
> ZN> Because of this, $123 is an invalid name, but why $000 or $00 works?
> 
> I think it has something to do with regular expressions, you use
> $[1-9] for back references, and $0 is unused (?)
> 

This shouldn't be the reason, as $0 'contains the name of the program
being executed'.
-- 
Zeng Nan   
Simple is Beautiful.

PGP Key:  http://hobbit.homeunix.org


pgpopovrh3jC7.pgp
Description: PGP signature


Re: Why $000 is a valid variable name?

2004-11-18 Thread Peter Scott
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Zeng Nan) writes:
>According to "Learning Perl", a variable name should be "a letter or 
>underscore, and then possibly more letters, or digits, or underscores."
>But why $000 or $ works?

As also said in "Learning Perl", you should declare all your variables
with 'my':

% perl -le 'my $000'
Can't use global $000 in "my" at -e line 1, at end of line
Execution of -e aborted due to compilation errors.

Doesn't look like it works to me.

"Learning Perl" also talks about the variable $_.  That doesn't
fit the pattern either.  But you can use it according to the
rules Perl has for it; you just can't declare it with 'my'
because it belongs to Perl, not you.

$000 is the same sort of animal.  Leave it alone, unless you
want to write deliberately obfuscated programs.

-- 
Peter Scott
http://www.perldebugged.com/
*** NEW *** http://www.perlmedic.com/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]