http://qs321.pair.com?node_id=11111454


in reply to Re^2: One to one file output idiom
in thread One to one file output idiom

No, but >> for append does, though you must be sure the OUT-file doesn't exist already

C:\tmp\files>perl -pE"open STDOUT=>qq(>>$ARGV.ext); s/bla/drivel/" a b + c

There was a hack with Eskimo kiss } { in the -e but as I said I'm not experienced with one liners.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Replies are listed 'Best First'.
Re^4: One to one file output idiom
by Eily (Monsignor) on Jan 16, 2020 at 09:28 UTC

    You can't really use an eskimo kiss with -p. And it's equivalent to an END block so I'm not sure how that would help here.

    But the open STDOUT, qq(>$ARGV.ext); version does work when slurping the files with -p00, for example in the case of a global substitution.

      > But the open STDOUT, qq(>$ARGV.ext); version does work when slurping the files with -p00, for example in the case of a global substitution.

      -p00 irritates me, I suppose you mean the equivalent to -p -00 , which doesn't mean slurping the whole file, but reading by paragraph.

      Slurping is bound to anything bigger -0400

      C:\tmp\files>type x 1:onebla 2:onebla 3:onebla 1:twobla 2:twobla 3:twobla 1:threebla 2:threebla 3:threebla C:\tmp\files>perl -n00 -E"say'>>';print;say'<<'" x >> 1:onebla 2:onebla 3:onebla << >> 1:twobla 2:twobla 3:twobla << >> 1:threebla 2:threebla 3:threebla << C:\tmp\files>perl -n0777 -E"say'>>';print;say'<<'" x >> 1:onebla 2:onebla 3:onebla 1:twobla 2:twobla 3:twobla 1:threebla 2:threebla 3:threebla <<

      from perlrun

      -0[octal/hexadecimal]

      specifies the input record separator ( $/ ) as an octal or hexadecimal number. If there are no digits, the null character is the separator. Other switches may precede or follow the digits. For example, if you have a version of find which can print filenames terminated by the null character, you can say this:

      1. find . -name '*.orig' -print0 | perl -n0e unlink

      The special value 00 will cause Perl to slurp files in paragraph mode. Any value 0400 or above will cause Perl to slurp files whole, but by convention the value 0777 is the one normally used for this purpose.

      You can also specify the separator character using hexadecimal notation: -0xHHH..., where the H are valid hexadecimal digits. Unlike the octal form, this one may be used to specify any Unicode character, even those beyond 0xFF. So if you really want a record separator of 0777, specify it as -0x1FF. (This means that you cannot use the -x option with a directory name that consists of hexadecimal digits, or else Perl will think you have specified a hex number to -0.)

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

        Yup my bad, it should have been -0777, didn't test what I was saying :)