Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: One to one file output idiom

by LanX (Sage)
on Jan 15, 2020 at 18:26 UTC ( #11111454=note: print w/replies, xml ) Need Help??


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 :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11111454]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2022-01-22 18:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (63 votes). Check out past polls.

    Notices?