News for hackers. Stuff that matters.
Re:C++ has become a scripting language by jackmaney on Wednesday October 16, 2013 @08:20AM (#6559177)
Here's a Perl example. This isn't optimally compact, but this is more or less how I would write a script like this if I had to put it into production at $work (maybe with an extra check to make sure that exactly two command line arguments were provided).

  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;
Re:C++ has become a scripting language by prakashk on Wednesday October 16, 2013 @05:56PM (#6562362)
Perl5 v12 and up:

    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]
Re:C++ has become a scripting language by draegtun on Thursday October 17, 2013 @05:49AM (#6564385)
Here's a couple of interesting Perl alternatives:

  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>};
Re:C++ has become a scripting language by hsmyers on Wednesday October 16, 2013 @02:24PM (#6561258)
If version >= 5.10 you can drop the 'or die' and for that matter neither of the close statements are necessary(in any recent version).