in reply to perl -pie "???"

perl -nie 'print if $. > 1' # Better perl -ie '<>; print while <>'

Oops. I don't use -i enough to realize that the following text is an argument for it.

perl -ibak -n -e 'print if $. > 1' # Better perl -ibak -e '<>; print while <>'

Replies are listed 'Best First'.
Re^2: perl -pie "???"
by hv (Prior) on Aug 17, 2004 at 21:45 UTC

    In line with recent discussions of the flip-flop operator, here's the flipside:

    perl -ni -e 'print if 2 .. 0' file

    Hugo

      golf!
      2..!print
Re^2: perl -pie "???"
by Plankton (Vicar) on Aug 17, 2004 at 21:32 UTC
    Hmmm it must be how I am invoking perl.

    Here's the line I want to get rid of ...
    $ head -1 DAR_RH9_install/index.html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http:/ +/www.w3.org/TR/html4/loose.dtd">
    Here's what I tried ...
    $ perl -nie 'print if $. > 1' DAR_RH9_install/index.html Can't open perl script "print if $. > 1": No such file or directory $ perl -ie '<>; print while <>' DAR_RH9_install/index.html Can't open perl script "<>; print while <>": No such file or directory
    What the heck I am doing wrong here?

    Plankton: 1% Evil, 99% Hot Gas.
      Perl isn't seeing the -e switch. Anything immediately following the -i is assumed to be the backup extension, ie "perl -i.bak..." will create a backup named filename.bak and operate on the original.

      Use perl -i -e '...' (or -i.bak -e if you want a backup).

      The -i switch takes an optional backup extension, so you can no longer combine it with other following option flags in modern perls. Write it instead as:

      perl -ni -e '...' file

      Hugo

      Change perl -nie ... to perl -ni -e .... -i accepts an optional argument, so a space is needed after it.
      perl -ni -e 'print if $. > 1' filename