develooper Front page | perl.beginners | Postings from May 2007

Attempting to update files blanks them instead

Thread Next
Kent Frazier
May 14, 2007 06:34
Attempting to update files blanks them instead
Message ID:
First off, this is my first post to this list, so hello everyone.  I am
pretty new to Perl, and to programming in general, but I hope I can be of
help to some of you in the future.  Right now, though, I am pretty confused
because one of my programs is not working the way I expect it to, and I
can't find the error.

I am using Learning Perl (the llama book) to familiarize myself with the
language, and I haven't had any problems up til now, but while doing the
exercises in chapter 9, I ran into a problem.  The fourth exercise asks you
to write a program that goes through all of your previous programs and adds
a copyright line after the #! line.  The original files are supposed to be
backed up in the process.  I wrote something that I thought would work, but
it backed up the file and then blanked the new file (or never put anything
in it, at any rate).  Frustrated, I looked in the back of the book and
tailored my code to match the example code given.  The program still behaves
the same way.  If it is relevant, I am using ActivePerl 5.8.8 Build 820 on
Windows XP SP2.  The source code is below.  Can someone with a more honed
eye for this code tell me what I am doing wrong?

#!perl -w
use strict;

$^I = ".bak";
while (<>) {
    if ( /^#!/ ) {
        $_ .= "## Copyright (C) 2007 by Kent Frazier.\n";

Hope this doesn't end up being something too newbish, and thanks in advance
for all your help.


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About