about eval and stdin
- From: all.adr@xxxxxxxxxxxx (Adriano Allora)
- Date: Mon, 2 Jan 2006 12:48:27 +0100
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 | | | | | **************************************
.
- Follow-Ups:
- Re: about eval and stdin
- From: John Doe
- Re: about eval and stdin
- Prev by Date: RE: Heterogenous array
- Next by Date: Re: Heterogenous array
- Previous by thread: Heterogenous array
- Next by thread: Re: about eval and stdin
- Index(es):