http://www.perlmonks.org?node_id=998040


in reply to Re: Compilation error
in thread Compilation error

1. When do I use 'my' before an array and when don't I?
2. Now with this script I get an error. Does this code '{$a <=> $b}' work with only numbers?
#!/usr/bin/perl use strict; use warnings; my@array = qw(one two three four five six seven eight nine ten); print "The original array contains - @array \n"; my@sorted = sort {$a <=> $b} @array; print "The sorted array contains @sorted \n";

The original array contains - one two three four five six seven eight nine ten
Argument "one" isn't numeric in sort at C:\JPARK\JPERL\test.pl line 7.
Argument "two" isn't numeric in sort at C:\JPARK\JPERL\test.pl line 7.
Argument "three" isn't numeric in sort at C:\JPARK\JPERL\test.pl line 7.
. . . The sorted array contains one two three four five six seven eight nine ten