in reply to Why are lines being skipped in output?

I'm going to comment your script one line at a time - it really is an excellent opportunity to explain some good bits of Perl (presumably, that's just what the author of your book intended.) My comments are prefixed with a '###'.

#!usr/bin/env perl ### I suspect that you're retyping your code, since the ### above would fail with a "Bad interpreter" error: there ### is no such thing as "usr/bin/env" (note absence of ### initial '/'.) As well, the 'env' trick isn't usually ### necessary unless you're moving your script between ### radically different systems where Perl is located ### in different places; usually, "#!/usr/bin/perl" will do. ### In addition, you should always - yes, *always* - enable ### warnings (i.e., let the computer do your troubleshooting ### for you) - so that shebang line should also have a ' -w' ### added to its end. open (test, "@ARGV"); ### Problem #1: you're trying to use an array (@ARGV) where ### you should be using a string containing a filename. This ### _will_ break if @ARGV contains more than one element. ### Problem #2: Whenever you perform any system-related task ### - i.e., an operation that is external to Perl - you ### should always (yes, *always*) check the result. As a ### minor additional correction, you should elide any ### unnecessary punctuation in your Perl - and you should ### either use sentence-case or all-caps names for file ### handles. As a result, the corrected version of the above ### line should read ### ### open Test, $ARGV[0] or die "$ARGV[0]: $!\n"; while (<test>) { $_ =~ <test>; ### This line is a simple error, and should be omitted. chomp; ### This is unnecessary, since you're going to want ### the newline character when you print the output. ### Omit it. s/(th)/TH/gi; ### Neither grouping nor capturing are used in the ### above regex; therefore, the parentheses do ### nothing and should be omitted. print "$_\n"; ### If you omit the above 'chomp', it will become ### unnecessary to explicitly specify '$_' or '\n'. ### This line then simply becomes 'print;'. } close (test); ### Again, the parens are unnecessary. Omit them.

As a result, the entire script should look like this:

#!/usr/bin/perl -w open Test, $ARGV[0] or die "$ARGV[0]: $!\n"; while (<Test>) { s/th/TH/gi; print; } close Test;

Conversely, you could use Perl's "diamond operator" which will do the same thing without having to explicitly open the file that you've specified on the command line:

#!/usr/bin/perl -w while (<>) { s/th/TH/gi; print; }