http://qs321.pair.com?node_id=11111449


in reply to One to one file output idiom

Another suggestion of mine form the CB discussion:
perl -pwe 'open STDOUT, ">", "$ARGV.txt" if $last ne $ARGV; s/.*/\U$&/ +; $last = $ARGV' *.obj

Update: Using eof is a bit cleaner, but it still triggers at a wrong time, so it couldn't be used directly:

perl -pwe 'open STDOUT, ">", "$ARGV.txt" unless $e; $e = ! eof; s/.*/\ +U$&/' *.obj

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

Replies are listed 'Best First'.
Re^2: One to one file output idiom
by LanX (Saint) on Jan 15, 2020 at 18:44 UTC
    maybe try $. to catch the first line per file, like
    C:\tmp\files>perl -nE"say qq($.--$ARGV) if $.==1; $.=0 if eof " a b c 1--a 1--b 1--c

    Unfortunately I need to reset $. at the end of each file, which is kind of hacky! :/

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      Closing ARGV before it gets opened again would be the non hacky thing way to do it since it's shown in the doc, although it's a bit longer.

      Edit: choroba pointed out it was shown in the doc for eof not open