in reply to How can I use printf FORMAT strings for (Win32) shell globs?
Though I am far from a regex expert, I had a thought that I hadn't seen suggested yet: watching you use the first regex to extract $prefix, and then a second to extract $format from $prefix, you could actually combine the two extractions into the same regex: with nested parentheses, the arguments are assigned in the left-to-right order of the open-parenthesis (see perlretut#Extracting matches). Using this, plus stevieb's and kcott's excellent suggestions, my regex snippet would be:
use warnings; use strict; ... my ($prefix, $format, $count, $ext) = ($match =~ /(\w+)(%(\d+)d)\.(\w+ +)/) or die "cannot find match"; # EX: Img%04d.png printf(" \$prefix: >%s<\n", $prefix); # (\w+) => Img printf(" \$format: >%s<\n", $format); # (%...d) => %04d printf(" \$count: >%s<\n", $count); # (\d+) => 04 printf(" \$ext: >%s<\n\n", $ext); # (\w+) => png ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How can I use printf FORMAT strings for (Win32) shell globs?
by AnomalousMonk (Archbishop) on Jul 17, 2017 at 15:29 UTC |