Hi Mallik.

You asked this question yesterday. Here is a copy of my answer
to yesterday's post.

Rob


Mallik wrote:
>
> I have to compare numeric values as below
>
> if (($segsep == 13) || ($segsep == 10) || ($segsep == 0))
>
> Can I use the reg exp as below
>
> if ($segsep =~ /^(13|10|0)$/)
>
> My question is, is it adviceable to use reg exp for numeric values (entire
> value).
> If yes, why?
> If not, why?

No. Because it's slower, and because several different strings can have
the same numeric value.

  for ( qw/ 12 00012 1.2E1 / ) {
    print "Numeric match for $_\n" if $_ == 12;
  }

succeeds in all three cases, but clearly

  for ( qw/ 12 00012 1.2E1 / ) {
    print "Regexp match for $_\n" if /^12$/;
  }

would match for only the first value.

If you're looking for a more concise way of matching any of a list of numbers
then try

  if ( grep $segsep == $_, 13, 10, 0 )

HTH,

Rob





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to