I have a variable $max = -3; It can be $max = 3; I need to check if this variable is a positive/negative value.
The following pattern works for integers which may or may not have a leading plus or minus sign.
The POSIX example above only gives integers, not other real numbers...
^ # beginning of string \s* # optional leading whitespace [a-z A-Z] # match two letters (?
:\s*\d\s*) # six digits, with optional whitespace leading/trailing [a-z A-Z]?
@list = qw(5 4.4 0 -1.2 asdf 12asdf asdf12 1.2e3 0e0); foreach $thing (@list) Note that ("12asdf" * 1) equals 12...
Also note that the above example does NOT work for numbers in scientific notation.
So this is our fourth post of the Fibonacci project, and in this installment, we are going to take on Perl.
For those of you who don’t know about the Fibonacci project, you should read the first post, Fibonacci in C.
The only way I can think of to make it work for numbers in sci-notation would be to use a regular expression.
I don't like having to do that though because there is always room for exceptions when using regular expressions.
https://web.archive.org/web/20121026141031/ / Identification Types-v1-4[Regular Expression(@"^([ACEHJLMOPRSWXYacehjlmoprswxy][A-CEGHJ-NPR-TW-Za-ceghj-npr-tw-z]|Bb[A-CEHJ-NPR-TW-Za-cehj-npr-tw-z]|Gg[ACEGHJ-NPR-TW-Zaceghj-npr-tw-z]|[KTkt][A-CEGHJ-MPR-TW-Za-ceghj-mpr-tw-z]|Nn[A-CEGHJL-NPR-SW-Za-ceghjl-npr-sw-z]|Zz[A-CEGHJ-NPR-TW-Ya-ceghj-npr-tw-y])[0-9][A-Da-d ]$", Error Message = "NI Number must be in the correct format.")] There is a fixed format for National Insurance Number or NINO.