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

Re: change all occurances of string1 into string2

by roboticus (Canon)
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.


Comment on Re: change all occurances of string1 into string2
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (9)
As of 2014-08-23 17:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (175 votes), past polls