imran77 has asked for the wisdom of the Perl Monks concerning the following question:

I want to edit files and perlform complex operations, one way is to read line-by-line and after some changes move it physically to another file.

How I can write inplace code in a perl script instead of at command line.

Regards

Imran

Replies are listed 'Best First'.
Re: inplace editing code in script
by Corion (Patriarch) on Oct 16, 2008 at 10:57 UTC

    Use B::Deparse to turn a one-liner to a Perl script:

    Q:\>perl -MO=Deparse -pi -e "$_='Hello'" BEGIN { $^I = ""; } LINE: while (defined($_ = <ARGV>)) { $_ = 'Hello'; } continue { print $_; } -e syntax OK

    See perlvar for the variables used.

      Are you using this script in a file or at command line, kindly explain?

        B::Deparse is a module you can use to convert Perl oneliners into code that you can use in scripts. I'm not sure what else there is to explain between the usage example I've shown and the documentation I've linked to.