Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: problematice metashar regexp

by Stevie-O (Friar)
on Apr 27, 2004 at 18:53 UTC ( [id://348664]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to problematice metashar regexp

Also, if you're only doing character-by-character replacements, you may want to give tr/// a shot. You can do it all in one go:
# note that I used {} as the delimiter for tr/// $foo =~ tr{1234567890!@#$%^&*()-+=\\|~} {?/><:;[]{}poidjhgk5329%c1^};
This would also help prevent a potential problem: your hash maps '5' to ':' and '(' to '5'. If Perl happens to order your hash so keys finds the second of these first, Perl will change '('s in the string to '5's, then later on change those converted '5's to ':'s. tr/// does everything in one shot, so that sort of thing won't happen.
--Stevie-O
$"=$,,$_=q>|\p4<6 8p<M/_|<('=> .q>.<4-KI<l|2$<6%s!<qn#F<>;$, .=pack'N*',"@{[unpack'C*',$_] }"for split/</;$_=$,,y[A-Z a-z] {}cd;print lc

Replies are listed 'Best First'.
Re: Re: problematice metashar regexp
by Anonymous Monk on Apr 28, 2004 at 09:49 UTC
    This looks pretty darn good as well.

    Trying to play with this, can something like this work?

    my $str1="1234567890!@#$%^&*()-+=\|~"; my $str2="?/><:;[]{}poidjhgk5329%c1^"; $foo =~ tr{$str1}{$str2};
    thanks you so much!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://348664]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.