Here's the textbook way to do it (TIMTOWTDI of course, but
nevertheless):

##################################

use strict;
use warnings;
open(INFILE,"<BUS_SCHEDULE") || die "Couldn't open BUS_SCHEDULE for
reading!\n";
open(OUTFILE,">BUS_SCHEDULE.new") || die "Couldn't open BUS_SCHEDULE.new
for writing!\n";
while(<INFILE>){
        $_ =~ s/bus/magic_bus/gi; #g for every occurrence, i for
case-insensitive
        print OUTFILE $_;
}
close INFILE;
close OUTFILE;
rename("BUS_SCHEDULE.new","BUS_SCHEDULE") || die "Couldn't rename the
new file!\n"; #automatically kills the old file

###################################

Adding in the error checking and not using any magic may seem like extra
work, but in the end it really doesn't take much extra time and can save
you (or especially the next guy that has to look at your code) a lot of
time down the road.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to