
BillKSmith
Veteran
Nov 1, 2010, 7:57 AM
Post #2 of 4
(200 views)
|
|
Re: [michaelalanward] Writing to a file.
[In reply to]
|
Can't Post
|
|
Good style requires more than a minimum change. Always use strict and warnings. Always close all open files. Always check for errors in open. In more formal work, check print and close for errors also. Always use the three argument form of open (ref perldoc -f open). Always use lexical ($) filehandles.
use strict; use warnings; open my $SORTED, '>', 'sorted_test.txt' or die "cannot open ouput file\n"; open my $IN, '<', 'test.txt' or die "cannot open input file\n"; print {$SORTED} sort <$IN>; close $IN; close $SORTED; Good Luck, Bill
|