Your skill will accomplish what the force of many cannot |
|
PerlMonks |
Schwartzian transform deformed with impunityby biohisham (Priest) |
on Apr 22, 2012 at 16:23 UTC ( [id://966478]=perlquestion: print w/replies, xml ) | Need Help?? |
biohisham has asked for the wisdom of the Perl Monks concerning the following question:
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?
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...
Back to
Seekers of Perl Wisdom
|
|