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

C:\tmp\files>dir Datenträger in Laufwerk C: ist WINDOWS Volumeseriennummer: AE0B-3544 Verzeichnis von C:\tmp\files 15.01.2020 19:09 <DIR> . 15.01.2020 19:09 <DIR> .. 15.01.2020 18:51 12 a 15.01.2020 18:51 12 b 15.01.2020 18:51 12 c 3 Datei(en), 36 Bytes 2 Verzeichnis(se), 12.802.805.760 Bytes frei C:\tmp\files>perl -pE"open OUT => qq(>$ARGV.ext); select (OUT); s/bla/ +drivel/" a b c C:\tmp\files>type * a "bla bla" a.ext "drivel bla" b "bla bla" b.ext "drivel bla" c "bla bla" c.ext "drivel bla"

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.