The $a have any special meanning ?

Discussion in 'Perl Misc' started by sonet, Jun 30, 2007.

  1. sonet

    sonet Guest

    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...)
    sonet, Jun 30, 2007
    #1
    1. Advertising

  2. sonet

    Peter Wyzl Guest

    "sonet" <> wrote in message
    news:f64n0b$d1h$...
    > 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
    Peter Wyzl, Jun 30, 2007
    #2
    1. Advertising

  3. Petr Vileta <> 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/"
    Tad McClellan, Jul 1, 2007
    #3
  4. Petr Vileta <> wrote:
    > Tad McClellan wrote:
    >> Petr Vileta <> 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/"
    Tad McClellan, Jul 1, 2007
    #4
  5. On 2007-07-02 02:31, Petr Vileta <> wrote:
    > Tad McClellan wrote:
    >> Petr Vileta <> 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.hjp.at/ | -- Sam in "Freefall"
    Peter J. Holzer, Jul 2, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kikoz
    Replies:
    6
    Views:
    370
    Indentix, Inc.
    Jul 27, 2004
  2. simon lee
    Replies:
    9
    Views:
    2,086
  3. Mufasa
    Replies:
    7
    Views:
    350
    Mufasa
    Jun 11, 2007
  4. Weng Tianxiang
    Replies:
    7
    Views:
    1,257
    Paul Uiterlinden
    Sep 11, 2009
  5. Rudra Banerjee

    meanning of the for loop

    Rudra Banerjee, Mar 13, 2013, in forum: C Programming
    Replies:
    8
    Views:
    178
    BartC
    Mar 14, 2013
Loading...

Share This Page