Tuesday, October 14, 2008

File Handling

#!/usr/bin/perl -w

open (INFILE, "first.txt") or die "Input file: $!";
open (OUTF, ">second.txt") || die "Output file: $!";

while ( INFILE ) {
#Replace the "hi" with "Hello"
s/hi/Hello/g;
#print the input stream into the file "second.txt"
print OUTF $_;
}

No comments: