Jonathan has asked for the wisdom of the Perl Monks concerning the following question:

A pretty inane question from a pretty inane guy...
I wrote the following code today
# Sort list and remove first two elements (undef,undef, my @sorted_tables) = sort { $a cmp $b } @table_list; write REPORT_CSV while $table_name = shift @sorted_tables;
Can anyone think of a more elegant approach? (preferably avoiding using the extra array @sorted_tables)

When I grow up I want to be a boy genius
My son Harry

Replies are listed 'Best First'.
Re: Inane question
by kilinrax (Deacon) on Nov 23, 2000 at 22:34 UTC
    Simply subscript the array returned by sort, thusly:
    foreach $table_name ((sort { $a cmp $b } @table_list)[2..$#table_list] +) { # do stuff }
Re: Inane question
by snax (Hermit) on Nov 23, 2000 at 22:52 UTC
    Well, unless you really need to remind yourself that you're sorting lexically, drop the sort sub -- lexical is the default sort:
    #!/usr/local/bin/perl -w use strict; my @data = (<DATA>); print "Naked...\n\n"; for (sort @data) { print } print "\nNow defined....\n"; for (sort {$a cmp $b} @data) { print } exit; __END__ 1 3 2 merlyn 4 10 birthday 12 9
    Of course that doesn't address the "elegance" issue of the two undef values, but you already have a good answer for that :)