ok, thank you again.
the version with the exploded list in the regexp did non works very well (it substituted bot the first and the second element of the pattern with a string similar to this: (surname1|surname2)).
(but your second suggestion was perfect)
at this time I solved my problem in this way:

#!/usr/bin/perl -w

my @orig = ("pippo", "gambadilegno");
my @new = ("minnie", "topolino");
my $num = 0;
my $file_name = "ciccio.txt";


open (INPUT, $file_name);

while (<INPUT>)
{
foreach $orig (@orig){
s/$orig/$new[$num]/g;
$num ++;
print;
}
}

close (INPUT);


maybe it's not very clear or quick or something else but this work as I want - and at the page ten of the camel they wrote TMTOWTDI: I find my $way;


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Venerd́, 27 Dic 2002, alle 20:11 Europe/Rome, Dan Muey ha scritto:




1-

Have you tried doing the regex without the vars?
s/(name1|name2)/(surname1|surname2)/g;
Does that do what you want?
If not you need to write a regex that does what you want without vars then incorporate that into your vars.

2-

This may work, try :

{
s/$original/$new/g;
print;
}

Dan



-----Original Message-----
From: Adriano Allora [mailto:[EMAIL PROTECTED]]
Sent: Friday, December 27, 2002 1:00 PM
To: [EMAIL PROTECTED]
Subject: single quote and substitutions


Hi to all,
I need to substitute in a text a serie of word with another serie of
word (for example: when I have the name I want the correct surname). Modifying a someone else script I wrote this one:


#!/usr/bin/perl -w

my $original = '(name1|name2)';
my $new = '(surname1|surname2)';

$file_name = "ciccio.txt";

open (INPUT, $file_name);

while (<INPUT>)
{
s/$original/$new/g;
$cortext .= $_;
}

print $cortex;

close (INPUT);

(first)It doesn't work correctly (it substitutes each $original with
the entire string "(surname1|surname2)"), and I'm not able to
understand why.
(second)Another thing: How can I write again, in a way more elegant,
the part:

$cortext .= $_;
}
print $cortex;

for example having only

}
print;

?

(third) have an exaordinary new year (and new years eve), I'm gratefull
to all af you beacuse it is useful to read your mail also when I'm not
directly interested by their subject.

all'adr


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to