Well, I guess I got away with this in some magical way I can't fathom in a Perl 5.12.4, I confess I was being abusive when tried to numerically compare some group of character strings which contained a number with the purpose of sorting them, the guilty feeling of seeing the warnings is irksome. I have a list of files that I want to sort orderly based on the number in their names and I thought I will achieve that through a Schwartzian transform. My files have the format of 'sequence<n>.gb.txt' where <n> is any number.

What my code does is that it goes around the directory picking these file names and feed that into an array, even though the files are arranged in the directory they are not in that array, so doing @sorted = map{$_->[0]} sort{$a->[2]<=>$b->[2]} map{[$_,split/sequence/]} @unsorted was my option, trying various combinations to split finally landed me in the direction (I tried splittig around /./ or /\d+/..etc). It is clear that sort() is so generous, I tried cmp (just to test what the output looks like). The code sorts @unsorted and yet complains of 'arguments being not numeric in numeric comparison (<=>)' blah blah

So Perl's sort() gracefully understood what I mean yet I got forgiving-ly pinched,I wonder as to how I can best evade introducing such warnings (going "no warnings" of course is not an option for me;)), any ideas?

use strict; use warnings; my @unsorted; my @sorted; while(my $file = <DATA>){ chomp $file; push @unsorted, $file; } @sorted = map{$_->[0]} sort{$a->[2] <=> $b->[2]} map{[$_, split/sequen +ce/]} @unsorted; print join("\n",@sorted); __DATA__ sequence3.gb.txt sequence1.gb.txt sequence7.gb.txt sequence5.gb.txt sequence2.gb.txt sequence4.gb.txt sequence10.gb.txt sequence9.gb.txt sequence8.gb.txt
##OUTPUT## Argument "1.gb.txt" isn't numeric in numeric comparison (<=>) at SortQ +uestion.pl line 11, <DATA> line 9. ... ... sequence1.gb.txt sequence2.gb.txt sequence3.gb.txt sequence4.gb.txt sequence5.gb.txt sequence7.gb.txt sequence8.gb.txt sequence9.gb.txt
UPDATE:Apparently the powers of a Schwartzian ensemble are so crazy


David R. Gergen said "We know that second terms have historically been marred by hubris and by scandal." and I am a two y.o. monk today :D, June,12th, 2011...

In reply to Schwartzian transform deformed with impunity by biohisham

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.