Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

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

Comment on Re: RegEx & Approach Question
Download Code

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 musing on the Monastery: (4)
As of 2015-11-27 00:08 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (710 votes), past polls