The $a have any special meanning ?

S

sonet

1.pl
----------------------
use strict;
$a=1;

the perl does not return error (Global symbol "$a" requires explicit package
name...)

but

2.pl
 
P

Peter Wyzl

sonet said:
1.pl
----------------------
use strict;
$a=1;

the perl does not return error (Global symbol "$a" requires explicit
package name...)

but

2.pl
----------------------
use strict;
$c=1;

the perl return error (Global symbol "$c" requires explicit package
name...)

$a and $b are special reserved variables used in sorting. perldoc -f sort

You can use them, but it is not good practice.

In fact single letter variable names are rarely good practice, particularly
when you need to re-edit that code in a years time...

P
 
T

Tad McClellan

Petr Vileta said:
Are you sure? I found examples in perldoc -f sort but these are examples.
Nowhere is mentioned about $a as special variable. In perlvar are mentioned
variables where second (third) character is not alphabetic, for example $`,
$/ etc. and only few alphabetic variables as @ARGV, @INC etc.


From perlvar.pod:

=item $a

=item $b

Special package variables when using sort(), see L<perlfunc/sort>.
Because of this specialness $a and $b don't need to be declared
(using use vars, or our()) even when using the C<strict 'vars'> pragma.
Don't lexicalize them with C<my $a> or C<my $b> if you want to be
able to use them in the sort() comparison block or function.
 
T

Tad McClellan

Petr Vileta said:
What version of Perl are you using?

5.8.8


I use 5.6.1


A lot has happened in the last 6 years.

Maybe this was be changed in 5.8.x ?


If you use ancient software, you should expect to miss out on a lot.
 
P

Peter J. Holzer

heh, I expected this ;-)

Yes, I know but Perl 5.8.0 looked as any version of Windows - it is stable
and usable 2-3 years after releasing :) Windows98 was be usable in year
2000, WinXP was be usable in year 2005, Windows Vista will be usable in year
2009? And Perl 5.8.x ? Yes, version 5.8.8 is usable with small problems and
version 5.8.10 will be stable as 5.6.1 is now :)

Huh? Software doesn't get more usable just with time. It needs to be
fixed. perl 5.6.1 hasn't seen any fixes in the last 6 years and was
released only one year after 5.6.0, so it can't be usable by your own
definition. The perl 5.8.x series OTOH is now 5 years old and should
have reached usable status per your "2-3 years" definition with release
5.8.5.

Perl 5.6.x is actually getting less usable as module authors stop
worrying about compatibility with it.

hp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top