Вопрос

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?

Это было полезно?

Решение

From perldoc strict

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

Другие советы

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top