in reply to clobbering output

You read and modify $_, but it doesn't print.

Replies are listed 'Best First'.
Re^2: clobbering output
by bluethundr (Pilgrim) on Feb 25, 2008 at 06:35 UTC
    I've added a print to the program, as per your suggestion. Well, it's still clobbering the output. However, now instead the output files, instead of being completely blank, have the shebang line and the copyright line, then the rest is completly obliterated. None of the text that was previously there, aside from the shebang line, are there.

    Right now, the code looks like this:
    #!/usr/bin/perl use strict; use warnings; $^I = ".old"; while (<>) { if (/^#!/) { $_ .= " ## Copyright (C) 2008 me\n"; print; } }


    I have to say, that a lot of this discussion is completely over my head. To anyone kind enough to repond, please try to bear in mind that I am working on chapter 9 in the Llama book. Thanks!
      What happens if you move the print outside of the if construct?

      CountZero

      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      Just to make CountZero's good suggestion more obvious, your code should probably look like this:

      #!/usr/bin/perl use strict; use warnings; $^I = ".old"; while (<>) { if (/^#!/) { $_ .= " ## Copyright (C) 2008 me\n"; } print; }

      The way you had it, the print would only happen on the line where you made the change. This way, every line is printed, whether you changed it or not.