Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: One to one file output idiom

by LanX (Saint)
on Jan 15, 2020 at 18:11 UTC ( [id://11111451]=note: print w/replies, xml ) Need Help??


in reply to One to one file output idiom

as I suggested in the CB do the open explictely:

I'm not good with one-liners, but this seems to do the job on Windows

>perl -pE"open OUT => qq(>$ARGV.ext); select (OUT); s/bla/drivel/" a b + c

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^2: One to one file output idiom
by choroba (Cardinal) on Jan 15, 2020 at 18:19 UTC
    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]
      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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-18 00:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found