in reply to unicode string comparison (perl 5.26)

Your comments suggest that you are trying to determine whether or not the string in $last is a valid number. Neither of your attempts will do this (Not even with the syntactic corrections already posted). It is not clear what you mean by 'number'. If you mean an unsigned decimal integer, your first try is on the right track. A string is almost certainly an integer if it does not contain any non-digits ("\D").

if($last =~ m/\D/) { ... # Process as a non-integer string else { ... # Process the integer }

For any other definition of 'number', you probably should use a module.

Your error message is almost certainly from an unrelated problem. Fix this much and then post the offending code.

Bill

Replies are listed 'Best First'.
Re^2: unicode string comparison (perl 5.26)
by Tux (Canon) on Nov 02, 2019 at 14:31 UTC

    I don't know if that will address the OP's problems:

    $ perl -wE'"6\x{0666}\x{07c6}"=~/\D/ or say "All digits"'
    All digits
    $ perl -Mutf8 -wE'"6٦۶߆६৬੬૬୬௬౬೬൬෬๖໖༦၆႖៦᠖᥌᧖᪆᪖᭖᮶᱆᱖꘦꣖꤆꧖꧶꩖꯶6𐒦𑁬𑃶𑄼𑇖𑋶𑑖𑓖𑙖𑛆𑜶𑣦𑱖𑵖𖩦𖭖𝟔𝟞𝟨𝟲𝟼𞥖6"=~m/\D/ or say "All digits!"'
    All digits!
    

    Enjoy, Have FUN! H.Merijn
      My English/ASCII only background has certainly left me with tunnel vision concerning what is a 'digit'. My algorithm is correct, but the OP will probably have to change the character class to reflect his requirement.
      Bill
Re^2: unicode string comparison (perl 5.26)
by afoken (Chancellor) on Nov 02, 2019 at 17:44 UTC
    A string is almost certainly an integer if it does not contain any non-digits ("\D").

    Almost:

    >perl -e 'for ("1", "22", "abc", "1e4", "0xABCD", "") { /\D/ or print +"\"$_\" is an integer\n" }' "1" is an integer "22" is an integer "" is an integer >

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
      I intentionally ignored unlikely exceptions such as a null string or any 'integer' which cannot be represented exactly in perl's floating point format.
      Bill