Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Substitution problem.

by Fastolfe (Vicar)
on Nov 25, 2000 at 05:45 UTC ( [id://43282]=note: print w/replies, xml ) Need Help??


in reply to Substitution problem.

First of all, you're only using the /g flag, which will interpret your expressions literally and do interpolation. So you end up with this:
s/quotemeta('[')/quotemeta('x')/g;
Which presumably (if it were valid) would match the text "quotemeta'['", putting '[' into $1. Try doing this:
s/\Q$array1{$count}\E/$array2{$count}/g;
Or, if each array element simply has one character apiece (as you suggest), forego the loop entirely and use tr:
$from = join('', @array1); # or set up $from and $to $to = join('', @array2); # to begin with tr/$from/$to/; # e.g. "abc" =~ tr/ab/xy/ ==> "xyc"

Replies are listed 'Best First'.
Re: Substitution problem.
by Dominus (Parson) on Nov 25, 2000 at 08:47 UTC
    Says fastolfe:
    > tr/$from/$to/;
    This won't work, because variables are not interpolated inside of tr///. Your line replaces $ with $; f with t; and r, o, and m with o.
      Indeed, so that one would want to use:
      eval("tr/$from/$to/");
      More and more the only place I end up using eval is in this type of construction.

        I hope neither $from or $to have a / in them...

        I actually use eval for quite a few things. For instance I may want to turn a template into code and then eval that. But for "quick-n-dirty" I don't reach for it with the obvious exception of the /e modifier for substitutions.

Log In?
Username:
Password:

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

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

    No recent polls found