Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: One to one file output idiom

by choroba (Cardinal)
on Jan 15, 2020 at 18:19 UTC ( [id://11111453]=note: print w/replies, xml ) Need Help??


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

Does it work if the files have more than one line? It seems the open overwrites the output file every time...

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^3: One to one file output idiom
by LanX (Saint) on Jan 15, 2020 at 18:26 UTC
    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

      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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-19 20:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found