Question

The following code has unusual behaviour that I found to be odd. It's just part of a program that works otherwise.

 #!/usr/bin/perl -w

    use strict;

    $a = 0;
    $abc = 0;                                                                                       

 exit 0;

Due to use strict statement Perl insists that I modify the second declaration as:

my $abc = 0;

But it does not do so for $a! I tried this on multiple Linux distros and Perl versions. Could anyone explain the reason please?

Était-ce utile?

La solution

From perldoc strict

Because of their special use by sort(), the variables $a and $b are exempted from this check

Autres conseils

$a is used for sort() and as such doesn't require declaration.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top