Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Check String

stephenlimstephenlim Member Posts: 20
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!

Comments

  • drzarkovdrzarkov Member Posts: 57
    : 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]
  • JonathanJonathan Member Posts: 2,914
    : 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.

    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.");

  • JonathanJonathan Member Posts: 2,914
    : [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.");

  • drzarkovdrzarkov Member Posts: 57
    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.");
    :
    :

Sign In or Register to comment.