in reply to most efficient buffer sort

use Sort::Key qw(ikeysort); my $buffer; open (INPF,"<input.dat") or die "Can't open input.dat: $!\n"; for (ikeysort {/^\w+\s+(\d+)/; $1} <INPF>) { m/^(\w+)\s+(\d+)\s+(\w+)(.*)$/ or die "Unable to match any lines:$!\ +n"; if ($2 < 90) { $buffer .= "<tr bgcolor='#00FF00'><td>$1</td><td>$2</ +td><td>$3</td><td>$4</td></tr>\n"; } elsif ($2 < 180) { $buffer .= "<tr bgcolor='#FF6600'><td>$1</td><td>$2</td><td>$3</td +><td>$4</td></tr>\n"; } else { $buffer .= "<tr bgcolor='#FF0000'><td>$1</td><td>$2</td><td>$3</td +><td>$4</td></tr>\n"; } } close INPF;

Replies are listed 'Best First'.
Re^2: most efficient buffer sort
by Anonymous Monk on Dec 14, 2005 at 12:33 UTC
    This is good stuff. However, having downloaded your CPAN module. Note that I changed the code above so it does a descending sort e.g.
    for (rikeysort {/^\w+\s+(\d+)/; $2} <INPF>) {
    This error now occurs
    Can't call method "rikeysort" on an undefined value at ./x.pl line 401 +, <INPF> line 12.
    There are only 12 records in my test input file
    It works fine if I use ascending key sort
    Any ideas what is happenning here ?
      have you changed the use Sort::Key statement to import rikeysort instead of ikeysort?
      use Sort::Key qw(rikeysort);
        Oops, schoolboy error. It works fine now. Many thanks.