Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > The $a have any special meanning ?

Reply
Thread Tools

The $a have any special meanning ?

 
 
sonet
Guest
Posts: n/a
 
      06-30-2007
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...)


 
Reply With Quote
 
 
 
 
Peter Wyzl
Guest
Posts: n/a
 
      06-30-2007
"sonet" <(E-Mail Removed)> wrote in message
news:f64n0b$d1h$(E-Mail Removed)...
> 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

 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      07-01-2007
Petr Vileta <(E-Mail Removed)> wrote:
> Thomas Wasell wrote:
>> Yes, $a and $b are special. See
>>
>> perldoc -f sort
>>
>> and
>>
>> perldoc perlvar
>>
>> for more information.

> 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.


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      07-01-2007
Petr Vileta <(E-Mail Removed)> wrote:
> Tad McClellan wrote:
>> Petr Vileta <(E-Mail Removed)> wrote:
>>> Thomas Wasell wrote:
>>>> Yes, $a and $b are special. See
>>>>
>>> Are you sure? I found examples in perldoc -f sort but these are

>>
>> From perlvar.pod:
>>
>> =item $a
>>
>> =item $b
>>

> 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.


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
 
Reply With Quote
 
Peter J. Holzer
Guest
Posts: n/a
 
      07-02-2007
On 2007-07-02 02:31, Petr Vileta <(E-Mail Removed)> wrote:
> Tad McClellan wrote:
>> Petr Vileta <(E-Mail Removed)> wrote:
>>> I use 5.6.1

>>

> heh, I expected this
>
>> A lot has happened in the last 6 years.
>>

> 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

--
_ | Peter J. Holzer | I know I'd be respectful of a pirate
|_|_) | Sysadmin WSR | with an emu on his shoulder.
| | | http://www.velocityreviews.com/forums/(E-Mail Removed) |
__/ | http://www.hjp.at/ | -- Sam in "Freefall"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
meanning of the for loop Rudra Banerjee C Programming 8 03-14-2013 11:48 AM
Are there any HD-DVD's that have extra special features..? Sandoz DVD Video 0 02-21-2008 08:15 PM
Special Report: How special are you? Death from Above MCSE 2 03-19-2007 07:22 PM
501 PIX "deny any any" "allow any any" Any Anybody? Networking Student Cisco 4 11-16-2006 10:40 PM
Special editions and Deluxe special edition dvd question. Rclrk43 DVD Video 8 12-29-2004 07:32 PM



Advertisments