in reply to Re^2: opening many files
in thread opening many files
That's because glob returns the results of datafile* interpolated in the order a shell would return them, so datafile11 comes before datafile2, as you've seen. A quick and dirty solution, if you know you're only dealing with up to 3 digits:
@ARGV = glob 'datafile? datafile?? datafile???';
A more general solution that'll sort on any number of digits:
@ARGV = sort { my $an = substr $a, 8; my $bn = substr $b, 8; $an <=> $ +bn } glob 'datafile*';
Aaron B.
Available for small or large Perl jobs; see my home node.
|
|---|