in reply to Re: Inserting Text into Files within a Directory
in thread Inserting Text into Files within a Directory

How do I create a temporary file? It cannot open $new because it is not defined...
  • Comment on Re^2: Inserting Text into Files within a Directory

Replies are listed 'Best First'.
Re^3: Inserting Text into Files within a Directory
by bgreenlee (Friar) on Aug 24, 2004 at 15:15 UTC

    Your best bet is to step through your code with the debugger (run it with perl -d) and see what the values of $dir and $file are before the call to open. See perldebug if you're unfamiliar with the debugger.

    Also, you have use warnings and use strict commented out in your program. Uncomment them and see what happens.

    -b

Re^3: Inserting Text into Files within a Directory
by bgreenlee (Friar) on Aug 24, 2004 at 15:34 UTC

    First of all, don't ask a new question by editing your previous one and replacing the text. It makes my above reply look completely irrelevant.

    As for creating a temporary file, there are lots of ways to do it. One that might work for you is to just add an extention on the name of the existing file:

    open(NEW,">$dir/$file.new") or die "Can't open $dir/$file.new: $!"

    -b

      Sorry, I'm new at this..I just updated my entire post again(with new code, etc.). Should I just create a completely new post when updating my questions?
        Should I just create a completely new post when updating my questions?

        If the "update" is significantly different from your original question, then yes, it might be a good idea to start a whole new thread. If it's just a minor clarification, a reply will usually work. Either way, it's considered bad form to change a post without (1) leaving the original intact (though sometimes <strike> is used to indicate retracted parts), and (2) clearly indicating an update has occurred. See 'How do I change/delete my post?' for more explanation.