in reply to Conditionals within Regex
That code has a subtle bug in it. If the regex doesn't match, $1 will still be set to its previous value...print "match\n" if (/(\d{1,3})%/, $1>91);
Replacing the comma with && will fix it.#!/usr/bin/perl -w use strict; "abc 123" =~ /(\d+)/; $_ = "its a tub of lard"; print "'$_' matches\n" if (/(\d{1,3})%/, $1>91); __END__ 'its a tub of lard' matches
In general, don't use $1 and friends without first checking that the regex you think they belong to actually matched.if (/(\d{1,3})%/ && $1>91);
-Blake
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Conditionals within Regex
by jlf (Scribe) on Sep 16, 2002 at 04:24 UTC |