: How to check the scalar is a string? Lets assume we have : my $str = "Hello world"; : : How to determine the $str is a string? Thanks! : as far as I know, you can only check if the scalar contains a non-digit character:
[code] if($str =~ /D/) { print $str." is a string "; } [/code]
: How to check the scalar is a string? Lets assume we have : my $str = "Hello world"; : : How to determine the $str is a string? Thanks! What do you mean by determining if it's a string? Perl(5) is generally untyped and things are stringified/numified as they are put into functions that require that kind of input. A number can be stored as a string, but I don't know that you should care whether it is or not.
oh yeah...I forgot....then it gets much more complicated....
like powers:
[code] $digit = 10**50; # would be 1.e+50 [/code]
: : [code] : : if($str =~ /D/) { : : print $str." is a string "; : : } : : [/code] : : What about real numbers such as 2.5? They contain a ., which isn't a digit, but they sure are numerical, if we care to make the distinction in Perl 5. : : Jonathan : : ### : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&& : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X; : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1."); : :
Comments
: my $str = "Hello world";
:
: How to determine the $str is a string? Thanks!
:
as far as I know, you can only check if the scalar contains a non-digit character:
[code]
if($str =~ /D/) {
print $str." is a string
";
}
[/code]
: my $str = "Hello world";
:
: How to determine the $str is a string? Thanks!
What do you mean by determining if it's a string? Perl(5) is generally untyped and things are stringified/numified as they are put into functions that require that kind of input. A number can be stored as a string, but I don't know that you should care whether it is or not.
What exactly are you trying to do?
Jonathan
###
for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
(tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
/(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
: if($str =~ /D/) {
: print $str." is a string
";
: }
: [/code]
What about real numbers such as 2.5? They contain a ., which isn't a digit, but they sure are numerical, if we care to make the distinction in Perl 5.
Jonathan
###
for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
(tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
/(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
like powers:
[code]
$digit = 10**50; # would be 1.e+50
[/code]
: : [code]
: : if($str =~ /D/) {
: : print $str." is a string
";
: : }
: : [/code]
:
: What about real numbers such as 2.5? They contain a ., which isn't a digit, but they sure are numerical, if we care to make the distinction in Perl 5.
:
: Jonathan
:
: ###
: for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
: (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
: /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
:
: