arunvelusamy has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks,
When i run the above code i get following error.#!/usr/local/bin/perl use strict; use warnings; my $a = [1, 2, 5, 7, 4]; print sort { $a <=> $b } @$a;
Can't use "my $a" in sort comparison at /home/code/perl/arrayprob.pl l +ine 5.
but when i use it as
the code works. Why do i get this error when i use $a or $b?my $ab = [1,2,5,7,4]; print sort { $a <=> $b } @$ab;
Thanks,
ArunVelusamy
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Error Sorting Array Reference?
by davorg (Chancellor) on Apr 25, 2006 at 10:25 UTC | |
Re: Error Sorting Array Reference?
by GrandFather (Saint) on Apr 25, 2006 at 10:28 UTC | |
Re: Error Sorting Array Reference?
by cdarke (Prior) on Apr 25, 2006 at 10:28 UTC | |
Re: Error Sorting Array Reference?
by pKai (Priest) on Apr 25, 2006 at 11:16 UTC | |
Re: Error Sorting Array Reference?
by Tomte (Priest) on Apr 25, 2006 at 16:02 UTC | |
Re: Error Sorting Array Reference?
by mantadin (Beadle) on Apr 25, 2006 at 10:28 UTC | |
Re: Error Sorting Array Reference?
by wazoox (Prior) on Apr 25, 2006 at 10:51 UTC | |
Re: Error Sorting Array Reference?
by Andrew_Levenson (Hermit) on Apr 25, 2006 at 16:49 UTC |