in reply to In-place editing of files (was: general perl question)

You want to use the -i and -p options. Do a perldoc perlrun for a complete list of Perl options.

Your script should look like:

#!/bin/perl -w -i .bak -p s/foo/toto/g; s/^\s*//;

This will do the substitution on each line of the file(s) passed as arguments and save the original files with a .bak suffix.

Replies are listed 'Best First'.
Re: Re: general perl question
by Rosencrantz (Initiate) on Apr 25, 2001 at 00:22 UTC
    mirod's reply is probably what you want.

    If you'd like to do this in a program, set the $^I variable (same thing as -i on the cmd line) to .bak or whatever. Or don't set it, and you'll just write over the file. Make sure @ARGV is set to the file name(s), either via the cmd line or in the program.