|
Posted by J. Gleixner on February 29, 2008, 5:41 pm
Please log in for more thread options
szr wrote:
> Joost Diepenmaat wrote:
>>
>>> which in fact does print the 4711 (a German "magic" number) with Perl
>>> 5.8.2, thus no side effects of the sorting (except of course that the
>>> missing "my" in front of $a does not cause an compile error.
>>>
>>> Is there any example to prove his impertinence of questioning the
>>> gurus' wisdom?
>> I would think:
>>
>> sub srt {
>> my @arr = qw /x a u q r/;
>> @arr = sort { $a cmp $b } @arr;
>> }
>>
>> srt();
>> my $a = 4711;
>> print "$a\n";
>>
>> versus:
>>
>> srt();
>> my $a = 4711;
>> print "$a\n";
>>
>> sub srt {
>> my @arr = qw /x a u q r/;
>> @arr = sort { $a cmp $b } @arr;
>> }
>>
>> would be enough reason not to use $a and $b.
>
> When I try the latter, I get the following, using Perl 5.8.8:
>
> Can't use "my $a" in sort comparison at line 9.
>
> 0001: #!/usr/local/bin/perl -w
> 0002: my @arr = srt();
> 0003: my $a = 4711;
> 0004: print "$a\n";
> 0005: print join (', ', @arr);
> 0006:
> 0007: sub srt {
> 0008: my @arr = qw /x a u q r/;
> 0009: @arr = sort { $a cmp $b } @arr;
> 0010: }
>
>
> The error message itself seems to be wrong, or more percisely, the wrong
> error for the given situation. There is no "my" in the "sort { ... }"
> clause. Is this be a bug?
>
> Furthur, why does it generate an error in the first place?
Are you kidding??????????
You're supposed to get an error. That's the reason Joost
posted the very concise example - to show the OP why
it might be bad to use $a.
|