[Chicago-talk] detecting whether a scalar is number or a string.

Shawn Carroll shawn.c.carroll at gmail.com
Sun Jul 6 18:03:27 PDT 2008


Sorry, too quick to answer:
 $string =~ m/[[:digit:]]/;
-or-
$string =~ m/[[:alpha:]]/;

http://perldoc.perl.org/perlre.html#Regular-Expressions
For further instruction.


On Sun, Jul 6, 2008 at 7:41 PM, Richard Reina <richard at rushlogistics.com> wrote:
>
> Thanks for the reply but when I try:
>
> $string = "859684";
>
> if ($string =~ m/[:digit:]/) {
>    print "this is numeric\n";
> }
>
> I get:
>
> POSIX syntax [: :] belongs in character classes regex;
>
>
> ---- Chicago.pm chatter <chicago-talk at pm.org> wrote:
>>
>> On Sun, Jul 6, 2008 at 2:48 PM, Richard Reina <richard at rushlogistics.com> wrote:
>> > Hello and Happy Sunday to All,
>> >
>> > Can someone tell me please how I can test whether a string is number or not.
>> >
>> > so to differentiate from:
>> >
>> > my $string = "anssds";
>> >
>> > and
>> >
>> > $string = "5879873454";
>> >
>> > Thanks for your attention.  Have a great day!
>> > _______________________________________________
>>
>> $string =~ m/[:digit:]/;
>> -or-
>> $string =~ m/[:alpha:];
>>
>> --
>> shawn.c.carroll at gmail.com
>> Perl Programmer
>> Soccer Referee
>> _______________________________________________
>> Chicago-talk mailing list
>> Chicago-talk at pm.org
>> http://mail.pm.org/mailman/listinfo/chicago-talk
>>
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk
>



-- 
shawn.c.carroll at gmail.com
Perl Programmer
Soccer Referee


More information about the Chicago-talk mailing list