I have been trying to teach myself perl with a few books and am stuck on several exercises. The first is this:
Write a program that substitutes every occurrence of the string "th" (either or both letters can be capital) with the string "TH" in file part1.txt (attached). The program must print the entire file to standard output, not just the replaced lines.
The Unix command line should look like:
$ proj2_1.pl part1.txt
The output should look like:
BIG BLUE LOOKED TO BIG RED -- IBM received great publicity when its
Deep Blue chess machine beat THe world chess champion, Gary Kasparov.
Deep Blue is a supercomputer THat runs on THe IBM AIX version of THe
UNIX system. After THe computer won THe second game of THe match, THe
head of THe IBM team introduced to THe audience his consultant and THe
creator of UNIX, Lucent's legendary Dennis Ritchie. THe audience gave
Ritchie a standing ovation. Maybe Bell Labs should get its deserved
share of publicity in THis man vs. machine hyperbole.
-- Alex Lubashevsky, Warren, N.J. (Lucent Today 5/13/97)
That's what it is supposed to do. My code looks like this:
#!usr/bin/env perl open (test, "@ARGV"); while (<test>) { $_ =~ <test>; chomp; s/(th)/TH/gi; print "$_\n"; } close (test);
The problem is this, when it prints out the paragraph of text, it skips every other line like this:
BIG BLUE LOOKED TO BIG RED -- IBM received great publicity when its
Deep Blue is a supercomputer THat runs on THe IBM AIX version of THe
head of THe IBM team introduced to THe audience his consultant and THe
Ritchie a standing ovation. Maybe Bell Labs should get its deserved
-- Alex Lubashevsky, Warren, N.J. (Lucent Today 5/13/97)
Can anyone provide some insight?
In reply to Why are lines being skipped in output? by negzero7
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |