I'm not getting it, and I have two questions.
#!/usr/bin/env perl use strict; my $s = 'eabcde'; $s =~ tr/abcd/efgh/; print "$s\n";
Getting eefghe as a result. Fair enough.
I find in the archives that using variable strings requires eval. Yet when I try to implement this, I bomb out:
...gives the results:#!/usr/bin/env perl use strict; my $search = 'eabcde'; my $replace = 'efgh'; my $result = eval "tr/$search/$replace/"; print "$search\n"; print "$replace\n"; print "$result\n";
So how can I capture the result of the second tranliteration?eabcde efgh 0
My second question lies in making these strings more complicated -- to the point of containing regular expression metacharacters. Obviously I need to escape them, but both search and replace strings are quite long and contain many characters which will require massaging.
Is there a default module which does such escaping, or is there a CPAN module which does what I need?
In reply to doing tr/// on-the-fly? by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |