Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: RegEx & Approach Question

by snoopy (Deacon)
on Oct 10, 2007 at 23:31 UTC ( #644112=note: print w/ replies, xml ) Need Help??

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"; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://644112]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2016-07-01 18:53 GMT
Find Nodes?
    Voting Booth?
    What is your favorite alternate name for a (specific) keyboard key?

    Results (14 votes). Check out past polls.