http://www.perlmonks.org?node_id=11132576

LanX has asked for the wisdom of the Perl Monks concerning the following question:

Hi

Yesterday I needed a Perl one-liner ( -e ) to loop over ( -n ) several subtitle files glob*.srt to find those which are in sync with the video I had.

Hence I needed paragraph mode ( -00 ) to see the timestamps

=== FILENAME.srt === 672 00:35:09,358 --> 00:35:11,027 Ditto ...

trouble is cmd.exe doesn't do *glob expansion, and my git-bash didn't like the paragraph mode, most probably because of different understandings of line endings

I ended up with something like this

perl -00nE"BEGIN{@ARGV=<@ARGV>}say qq{=== $ARGV ===\n$_} if /ditto/i" *Filenames*

but the BEGIN block is a bit ugly.

Any more elegant way to do this?

One generic workaround could be a special module wglob to do the BEGIN part with perl -Mwglob but I'd like to ask the community first...

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re: One liner with globs on Windows to parse .srt files
by haukex (Archbishop) on May 14, 2021 at 11:11 UTC
      Yeah, that's basically the same idea, but a bit longish for a one-liner, don't you think?

      Using INIT{@ARGV=<*inlined-glob-pattern*>} has less characters ...

      update

      hmm wait tho ...

      ... I could use the ENV-var PERL5OPT to always preload that module for all Perl scripts in the current cmd.exe :)

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

        Yeah, that's basically the same idea, but a bit longish for a one-liner, don't you think?

        Dunno, seemed like the most straightforward answer to your question - just copy Win32\Autoglob.pm to wglob.pm ;-)

        ("'-M5;@ARGV=<*.srt>' -e'...'" actually doesn't save any characters over "-e'BEGIN{@ARGV=<*.srt>}...'")

        Update: Regarding PERL5OPT, sure!

Re: One liner with globs on Windows to parse .srt files
by Discipulus (Canon) on May 14, 2021 at 14:15 UTC
      Thanks, but this looks easier to me

      d:\tmp>set PERL5OPT=-MWin32::Autoglob d:\tmp>perl -E"say qq(@ARGV)" t_*.pl t_dump_folding.pl t_export_var.pl t_unicode.pl d:\tmp>

      and has the benefit that I can localize the effect to terminals which have this option activated.

      please note that sitecustomize.pl could be used for global settings of an installation, without the need to recompile Perl.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery