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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.