vendredi 27 février 2015

Perl : How to match data in entire text


Vote count:

0




In the following code i am trying to use data from "Input File 1" to edit data in "Input File 2". But the problem is the code is not able to match or substitute when the possible match text is anywhere other than at the last, towards right. Could you please help me in figuring out way to match it in the entire text.



I am still new to coding so if you find any other possible enhancements, i will highly appreciate your guidance.

###########################################################
#Input File 1
###########################################################
Saint st

Saint saint

Saint st.

Saint snt

Saint snt.

Hotel htl

Hotel htl.

Road rd

Road rd.
###########################################################
#Input File 2
###########################################################

Part.Name.

Gordon house st

Gordon saint house

Gordon st. house

Gordon snt house

Gordon snt. house

htl palace

htl. Indiana

nuav rd hotel

dankei hotel rd.
###########################################################
#Code Starts Here
###########################################################


use strict;
use warnings;
open (my $fh1, "< $filename1") or die $!;
my @incomin_data1=<$fh1>;
my $array_length1=$#incomin_data1;
my @key; my @value;
for (my $count=0;$count<=$array_length1;$count++)
{($key[$count],$value[$count])=split /,/,$incomin_data1[$count];}
my $key_length=$#key;
open (my $fh2, "< $filename2") or die $!;
my @incomin_data2=<$fh2>;
my $array_length2=$#incomin_data2;
for (my $count2=0;$count2<=$array_length2;$count2++)
{ for (my $count3=0;$count3<=$key_length;$count3++)
{ my $ky=$key[$count3];
my $val=$value[$count3];
if ($incomin_data2[$count2]=~/\s?$val\s?/g)
{ $incomin_data2[$count2]=~s/$val/$ky/; }}}
print "\n\n",@incomin_data2;


asked 1 min ago







Perl : How to match data in entire text

Aucun commentaire:

Enregistrer un commentaire