Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^5: One to one file output idiom

by LanX (Sage)
on Jan 16, 2020 at 20:34 UTC ( #11111497=note: print w/replies, xml ) Need Help??


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

> 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

Replies are listed 'Best First'.
Re^6: One to one file output idiom
by Eily (Monsignor) on Jan 17, 2020 at 08:57 UTC

    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://11111497]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2021-12-08 21:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (36 votes). Check out past polls.

    Notices?