develooper Front page | perl.beginners | Postings from December 2002

single quote and substitutions

Thread Next
From:
Adriano Allora
Date:
December 27, 2002 10:54
Subject:
single quote and substitutions
Message ID:
552C1008-19CD-11D7-B471-003065F0ECD2@mac.com
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


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About