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 |