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

Re: change all occurances of string1 into string2

by roboticus (Chancellor)
on Nov 29, 2012 at 18:16 UTC ( #1006318=note: print w/replies, xml ) Need Help??


in reply to change all occurances of string1 into string2

Mr. Newb:

There's a bit of a problem in the code. It may or may not affect you though:

#!/usr/bin/perl use strict; use warnings; my $orig="she sells sea shells down by the seashore\n"; my ($new1, $new2) = ($orig, $orig); my %translate=(she=>'shore', shore=>'sell', sell=>'she'); $new1 =~ s/$_/$translate{$_}/g for keys %translate; print $new1; #print join(", ", keys %translate), "\n"; my $FOO='0000'; $translate{$_}=9999-$_ for 1..10; $new2 =~ s/$_/$translate{$_}/g for keys %translate; print $new2; #print join(", ", keys %translate), "\n"; $ perl x.pl she shes sea shells down by the seashe shore shores sea shorells down by the seashore

Uncomment the two print statements to see why...

...roboticus

When your only tool is a hammer, all problems look like your thumb.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1006318]
help
Chatterbox?
[marto]: a co-worker refers to the late 1980s as "a while ago"
[Veltro]: Like I said before, I ment the solution as a whole
[Veltro]: People thought it was not possible.
[marto]: and until recently it wasn't and arguable (for some samples) probably isn't
[Veltro]: How did we get here? Oh yeah, advertisement. So let's get back there. What I ment to say is that I think it is possible to create an algorithm that filters out advertisement
[Veltro]: And yes, maybe your decoder needs the cloud to do so.
[marto]: for sane sources you should be able to do that locally

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2018-05-24 12:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?