Further to hippo's post: Note that going a step further and enabling strictures with usestrict; would have prevented the code from compiling in the first place:
c:\@Work\Perl\monks>perl -le
"use strict;
use warnings;
;;
my @ar = ([1,12],[8,3],[4,57],[22,5]);
my @sort = sort{$a[1]<=>$b[1]}@ar;
foreach (@sort){
print \"@$_\n\";}
"
Global symbol "@a" requires explicit package name at -e line 1.
Global symbol "@b" requires explicit package name at -e line 1.
Execution of -e aborted due to compilation errors.
(I have to admit the Global symbol "@a" requires explicit package name ... etc messages are slightly more obscure, but they explicitly point you to the offending variable.)
See also How do I sort an array by (anything)? in the Data: Arrays section of perlfaq4.
Give a man a fish: <%-{-{-{-<
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|