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?

Was it helpful?

Solution

From perldoc strict

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

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top