Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Distiguishing arguments: number-strings vs real integer

by wjw (Priest)
on Aug 09, 2018 at 23:32 UTC ( [id://1220166]=note: print w/replies, xml ) Need Help??


in reply to Distiguishing arguments: number-strings vs real integer

Do I misunderstand the question or will the following not work?

Edit: Ok, I misunderstand the nature of the problem as noted by LanX in Re^2: Distiguishing arguments: number-strings vs real integer... My apologies.

#!/usr/bin/perl use strict; use warnings; #use Data::Dump qw/pp dd/; #use Scalar::Util qw/looks_like_number/; #use Devel::Peek; sub is_string { my $arg = $_[0]; warn "$arg looks like number \n$&\n\n\n" if $arg =~ /(\d+)/; } is_string(1); is_string("42"); my $n=1; my $s="42"; my $s1="this contains the number 143"; my $s2 = "Awierd123number"; is_string($n); is_string($s); is_string($s1); is_string($s2); $n.=""; # cast to string $s+=0; # cast to number is_string($n); is_string($s);

...the majority is always wrong, and always the last to know about it...

A solution is nothing more than a clearly stated problem...

Replies are listed 'Best First'.
Re^2: Distiguishing arguments: number-strings vs real integer
by LanX (Saint) on Aug 10, 2018 at 00:19 UTC
    > Do I misunderstand the question ...

    I'm afraid you are. :)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1220166]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-25 09:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found