in reply to Converting to number doesn't always work...

$N =~ tr|[0-9]||cd;

NB: The first field of the  tr/// operator (see Quote-Like Operators in perlop) is a search list, and it does not "know" about  [...] character classes (the search list is itself a kind of character class), so the  [ ] characters are among the "digit" characters which are not deleted.

c:\@Work\Perl\monks>perl -wMstrict -le "my $n = 'abc[]1p2q3][xyz'; $n =~ tr|[0-9]||cd; print qq{'$n'}; " '[]123]['
Don't know about the rest of the question.


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^2: Converting to number doesn't always work...
by harangzsolt33 (Deacon) on Nov 22, 2019 at 05:55 UTC
    Oh, thanks for catching that!

    my $A = 'abcd0123456789ABCDE[]{}()_=|?<>!@~%$/.-'; print "\nBEFORE: $A"; $A =~ tr|[0-9]||cd; print "\nAFTER: $A"; # Output: 0123456789[]