Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using variables in a transliteration operator

Tags:

regex

perl

This is a stupid question; I need this for something more complicated but let's make it simple:

$i = quotemeta 'A';
$line =~ tr/a-z/$i-Z/;

This is a silly substitution, this should turn small letters to capital ones, but what ever I tried doesn't work.

Ok so I see this brought lots of confusion, the real code should be:

$line =~ tr/A-Z/F-ZA-E/;

It should be a Caesers Chiper algorhytm. This works just fine if you want to change it by a fixed number of letters, but I need a variable so I could change it as many number of letters as I want to. But I want to ship eval Thnx

P.S. Also, why doesn't s/// work with ranges?

like image 338
Zippie Avatar asked Dec 28 '22 01:12

Zippie


1 Answers

If you really need tr, you could use eval:

$i = quotemeta 'A'
eval("\$line =~ tr/a-z/$i-Z/;");
like image 162
happydave Avatar answered Jan 11 '23 02:01

happydave