biohisham has asked for the wisdom of the Perl Monks concerning the following question:
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
UPDATE:Apparently the powers of a Schwartzian ensemble are so crazy##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
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...
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Schwartzian transform deformed with impunity
by moritz (Cardinal) on Apr 22, 2012 at 16:39 UTC | |
Re: Schwartzian transform deformed with impunity
by jwkrahn (Abbot) on Apr 22, 2012 at 23:16 UTC | |
Re: Schwartzian transform deformed with impunity
by dave_the_m (Monsignor) on Apr 22, 2012 at 19:27 UTC | |
by jwkrahn (Abbot) on Apr 23, 2012 at 11:18 UTC | |
Re: Schwartzian transform deformed with impunity
by salva (Canon) on Apr 23, 2012 at 08:58 UTC |