http://www.perlmonks.org?node_id=966487


in reply to Schwartzian transform deformed with impunity

If the file format really is as fixed as you describe, with only the number component varying, then you could strip off everything except the number, sort the numbers, then print out or assign to an array while reconstructing the file name from the number:
use strict; use warnings; print map "sequence$_.gb.txt\n", sort { $a <=> $b } map { /(\d+)/; $1 } <DATA>; __DATA__ sequence3.gb.txt ....

Dave.

Replies are listed 'Best First'.
Re^2: Schwartzian transform deformed with impunity
by jwkrahn (Abbot) on Apr 23, 2012 at 11:18 UTC
    map { /(\d+)/; $1 }

    No, that is wrong.    If /(\d+)/ doesn't match then $1 will not contain valid data:

    $ perl -le' use Data::Dumper; my @y = map { /(\d+)/; $1 } qw/ ab123cd ab456cd abcdefg ab789cd /; print Dumper \@y; ' $VAR1 = [ '123', '456', undef, '789' ];

    Just use:

    $ perl -le' use Data::Dumper; my @y = map /(\d+)/, qw/ ab123cd ab456cd abcdefg ab789cd /; print Dumper \@y; ' $VAR1 = [ '123', '456', '789' ];

    The regular expression by itself will just do the right thing.