Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Converting to number doesn't always work...

by AnomalousMonk (Archbishop)
on Nov 22, 2019 at 05:24 UTC ( [id://11109043]=note: print w/replies, xml ) Need Help??


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 (Chaplain) 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[]

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11109043]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-04-24 23:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found