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

Re: How do I keep anything other than alphanumeric out of a variable?

by Roy Johnson (Monsignor)
on Nov 04, 2003 at 14:53 UTC ( [id://304434]=note: print w/replies, xml ) Need Help??


in reply to How do I keep anything other than alphanumeric out of a variable?

The right tool for character classes is tr///, not s///:

$user_name =~ tr/0-9a-zA-Z//dc;
(You can add the underscore character, or any others you like, of course.)

If you wanted the username to look like a valid Perl identifier (i.e., begin with a letter, then alphanumerics + underscores), you would then want to strip off the leading non-letters:

$user_name =~ s/^[^a-z]*//i;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-20 00:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found