in reply to Re: Not A Rockstar File Manipulator Today
in thread Not A Rockstar File Manipulator Today

S a typo? Does that mean you didn't copy and paste the code but wrote it down a second time? In that case are you sure both programs are identical now?

One thing you might do now is debugging. I.e. put print statements into you code to check the changes in $_. Your loop might look like this:

print "REPLACE <$pattern> with <$replacement>\n"; while (<IN>) { # print "<$_>\n"; S/$pattern/$replacement/g; print "AFTER <$_>\n"; print OUT $_; } # end while

Or you might use perls debugger where you can execute a line, look at any and all variables you like, execute the next line, look at .... Just call your script with perl -d and use 's' or 'n' to single step and 'p $_' to see the contents of variable $_, for example. 'h' gives you a help page. It is really simple and easy to work with, read 'man perldebug if you want to know more'

Replies are listed 'Best First'.
Re^3: Not A Rockstar File Manipulator Today
by mpeever (Friar) on Nov 15, 2008 at 00:49 UTC

    Inline debugging is really, really helpful in cases like this. You might also want to change the

    print OUT $_;
    to
    print ;
    to print your lines on the screen.

    And for a sanity check, you might put something like:

    print "\$in_file: $in_file \n"; print "\$out_file: $out_file \n"; print "\$pattern : $pattern\n"; print "\$replacement: $replacement\n";
    before your open commands. Just to make sure you're opening the file(s) you think you're opening.