in reply to Is Array Element Numeric? (was I wonder...)
#!perl -w # use strict; my @array = (100, 'a string!', 45.678, 0.43243, '', "", 0, "another no +rmal string with a carriage return \n"); foreach (@array) { if (/\D/) { print "$_ contains non-digits\n"; } elsif (/^\d+$/) { print "$_ is a whole number\n"; } elsif (/^-?\d+$/) { print "$_ is an integer\n"; } elsif (/^[+-]?\d+$/) { print "$_ is a +/- integer\n"; } elsif (/^-?\d+\.?\d*$/) { print "$_ is a real number\n"; } elsif (/^-?(?:\d+(?:\.\d*)?|\.\d+)$/) { print "$_ is a decimal number\n"; } elsif (/^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/) { print "$_ is a C float\n"; } else { print "$_ not a number format I recognise, bud.\n"; } }
|
|---|