about eval and stdin



hi to all,
a friend of mine ask me for a perl script to change regexp patterns in some texts (he can learn regexp, but I suppose he won't learn perl). So I start write this one to him.
I have a problem:


==> with pattern = (dir)ectory and replacement = $1, why the script does not eval $1 as "dir"? how I can change the script to make it works as I want?


#!/usr/bin/perl -w
$^I ='_old';
print "pattern: ";
$pattern = <STDIN>;
chomp($pattern);
print "replacement: ";
$replacement = <STDIN>;
chomp($replacement);
print "\n print \"s\" to confirm substitution; print \"n\" to avoid it print \"n\" \n\n";
while(<>)
{
$choice = "";
if(/$pattern/gi)
{
eval $replacement if $replacement eq "$1";
print STDOUT "I'd subsitute this one => ". $_;
$choice = <STDIN>;
chomp($choice);
}
s/$pattern/$replacement/gi if $choice eq "s";
print;
}


thank you all,

alladr


|^|_|^|_|^| |^|_|^|_|^| | | | | | | | | | |*\_/*\_/*\_/*\_/*\_/* | | | | | | | | | http://www.e-allora.net | | | | | **************************************

.