Perl regular expressions?

jkresh

Platinum Member
Jun 18, 2001
2,436
0
71
I just started working with perl today and have been doing some work with regular expressions, and have run into something of a snag. I want to find a pattern that I dont know what it will be, I know that the end will relate to the begining, and even know the relationship but dont know what the begining is. Example $test = "XYZCBA", where X coresponds to C, Y to B, and Z to A, I know that I can do

if ($test =~ /(.{3})/1/g)
do something;

but I want to do /1 =~ tr/ZYX/ABC;
or something along those lines, I know it could be done with a context free language, I also know that a Perl regular expression can do more then a regular, regular expression, but I dont know how to do this in perl. Thanks for the help.
 

jkresh

Platinum Member
Jun 18, 2001
2,436
0
71
Yes I meant X corresponds to C, the actual pattern doesnâ??t matter, I just need to know how to create it, I also donâ??t know the length of the pattern, but I know that the length of the first part is the same as the length of the next.
 

jkresh

Platinum Member
Jun 18, 2001
2,436
0
71
I think something like

$test =~ /(.{3}) (??{trans($1)})/g

sub trans {

$out = @_;
$out =~ tr/XYZ/CBA/g;
return $out;
}

might work but it doesnt seem to work right