And the clouds parted, and Nandita Mullapudi said...
>
> This has to be really easy- but I cant get it to work:
> I want my script to carry out a loop only if the number stored in
> $diff is positive,
> so i say
> if ($diff =~m/^[-\d+]/) {blah blah}
> but it won't work. why?
> TIA
> -Nandita
Hi Nandita,
The problem is that you're trying to match a character class instead of the
pattern you think you're matching.
Your pattern: ^[-\d+]
Which means : "At the beginning of the line, match a single dash, digit, or
plus sign."
In other words, it will match '-23 fnords', '42', '--Socrates', '++$foo', and
a slew of other things you never indended. :) A character class matches a
single character, no more.
What you probably want is the ($diff == abs($diff)) solution already proposed,
since you've stated that $diff should be a number.
That being said, the pattern you were trying for would probably be: \A-\d+\Z
Which says: "At the beginning of the string, match a single dash, followed by
one or more digits, followed by the end of the string."
HTH-
Brian
/~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\
| Brian Gerard I don't suffer from insanity. |
| First initial + 'lists' I enjoy every minute of it. |
| at technobrat dot com |
\______________________________________________________________________/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]