in reply to searching a string with variable data

# $_ contains a sentence. use \d+ for more numbers or \w+ for words if ( /see the \d brown foxes\. they are certainly fast\./ ) { # do something }
Boris

Replies are listed 'Best First'.
Re^2: searching a string with variable data
by ikegami (Patriarch) on Nov 29, 2004 at 23:47 UTC

    or, if you need to know the number, note the parens around the \d:

    my $count; if (($count) = /see the (\d) brown foxes/) { print("There are $count foxes. Let's go hunting!$/"); }

    Also, use \d+ if you want to match one or more digits, instead of just one.

Re^2: searching a string with variable data
by chb (Deacon) on Nov 30, 2004 at 07:14 UTC
    Lets not forget the 'certainly':
    if ( /see the \d brown foxes\. they are \w+ fast\./ ) { # do something }
    or with capturing (like ikegami pointed out)
    my ($count, $word); if (($count, $word) = /see the (\d) brown foxes\. they are (\w+) fast\ +./) { print("There are $count foxes. Let's go hunting!$/"); }