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


in reply to RegEx & Approach Question

String::Scanf's format_to_re method might be useful for parsing these patterns. It lets you setup regular expressions in an sprintf like format.
#!/usr/bin/perl use warnings; use strict; use String::Scanf qw(); sub scanf { my $pat = String::Scanf::format_to_re(shift); my $input = shift; return $input =~ /^${pat}$/; } my $format = "Input queue: %d/%d/%d/%d (size/max/drops/flushes); Total + output drops: %d"; my $input = "Input queue: 0/75/0/39 (size/max/drops/flushes); Total ou +tput drops: 19845805"; if (my ($size,$max,$drops,$flush,$total) = scanf($format, $input)) { warn "Gotcha: size=$size, max=$max,drops=$drops,flush=$flush,total=$ +total"; }