by jackmaney · 13y ago · 0 comments
use strict;
use warnings;
open my $read,"<",$ARGV[0] or die $!;
my @lines = <$read>;
close $read;
open my $write,">",$ARGV[1] or die $!;
print $write $line foreach my $line(sort @lines);
close $write; use v5.12; # enables strictures
open my $in, "<", $ARGV[0];
open my $out, ">", $ARGV[1];
print $out sort <$in>;
Perl6: sub MAIN( $in, $out ) {
spurt( $out, open($in, chomp => False).lines.sort.join )
}
[EDIT: fixed typo in first example] my @files = map { IO::File->new($_->[0], $_->[1]) || die $! }
([shift, 'r'], [shift, 'w']);
$files[1]->print( sort $files[0]->getlines );
$_->close for @files;
And... use autodie;
open my $out, '>', $ARGV[1];
print {$out} sort do {open my $in, '<', $ARGV[0]; <$in>};