Load an hash from a text file
From: Web Solving (websolving_at_gmail.com)
Date: 02/28/05
- Next message: Marcello: "Re: strange if-else problem"
- Previous message: Cristi Ocolisan: "Perl and Semantic web"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 28 Feb 2005 11:32:54 +0100 To: beginners@perl.org
Hi all, i'm a real perl newbie. i've a question for you all. i've to
perform a "search and replace" on a text file, and i wrote this:
open(READIT,"file.txt") || die "Cant read file.txt. Reason: $!";
open(WRITEIT,">>file_new.txt") || die "Cant write file_new.txt. Reason: $!";
while (<READIT>) {
if ($riga =~ /una pallina/) {
$riga =~ s/una pallina/un cobra/;
}
elsif ($_ =~ /cobra/) {
$riga =~ s/cobra/<\a href="http:\/\/www\.serpentoni.it>cobra<\/\a>/;
}
print WRITEIT "$riga\n";
}
close(WRITEIT);
close(READIT);
i need to load the corrispondence "world to be seek"=>"replaced word"
from another text file, like this:
word|<\a href="http:\/\/www\.word.it>word<\/\a>
the word|<\a href="http:\/\/www\.word.it>the word<\/\a>
a word|<\a href="http:\/\/www\.word.it>a word<\/\a>
word2|<\a href="http:\/\/www\.word2.it>word2<\/\a>
the word2|<\a href="http:\/\/www\.word2.it>the word2<\/\a>
a word2|<\a href="http:\/\/www\.word2.it>a word2<\/\a>
eccetera.....
so i think i can use an hash, but i can't
understand how i can load the txt file in an hash, i tried to search
the answer of my question in several tutorials but i can't find
anything about it. can u help me?
-- WebSolvingJaa: informatica per il web e l'azienda. http://websolvingjaa.altervista.org/
- Next message: Marcello: "Re: strange if-else problem"
- Previous message: Cristi Ocolisan: "Perl and Semantic web"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]