On Tue, 18 Nov 2003 16:37:06 +0000, Jabez Wilson wrote:
> Is it possible to specify number matching in a regex, i.e. can you have
> something like:
> 
> my $match =~ m/match_number_if_number_is_less_than_255/
> 
> instead of my $match =~ m/(\d{3})/;
> 
> if ($1<=255){my @array = @array +$1}?

Yes, but would you?  IMO, using regular expressions to check the value of
something creates less readable code.  I tend to prefer to first check if
I'm really dealing with a number, and then checking the value of it in a
good old fashion way;

  if ( $nr =~ m,^[-+]?\d+$, && $nr < 255 ) {
      # Match
  }

I don't need to write that regular expression every time, of course,
'cause I've been nice enough to put it in a module so that I only need to
write 'is_int($nr)' each time.

(And the actual implementation of the is_int() function is heavier; It
check if a number really _is_ a number - the above don't, really...)


-- 
Tore Aursand <[EMAIL PROTECTED]>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to