Hi People
I need to compare a particular line in a file with a particular string in the other file. I am attaching both the files for your reference.
here is my code:
open (INFILE, "$input") or die "Couldn't open $input for reading: $!\n";
while(<INFILE>)
{
my $line= $_;
$line=~tr/\n//d;
my($city,$country,$lan,$lat) = (split(/\t/))[0,1,2,3];
push(@aj1,"$city");
push(@aj2, "$country");
push(@aj3,"$lan");
push(@aj4,"$lat");
}
close(INFILE);
my $arr_size = $#aj1;
open (OUTFILE, ">$output") or die "Couldn't open $output for writing: $!\n";
open (INFILE2, "<$input2") or die "Couldn't open $input2 for reading: $!\n";
while(<INFILE2>)
{
my $lines=$_;
#$lines=~tr/\n//d;
print"$lines";
my($jass,$author,$add) = (split(/\|/,"$lines"))[0,1,2];
my $j=0;
for(my $i=0;$i<=$arr_size;$i++)
{
my $country1=$aj2[$i];
my $city1=$aj1[$i];
if(($add=~m/$country1/) && ($add=~m/$city1/))
{
if($j==0)
{
#print"$j";
$j=$j+1;
print OUTFILE"$lines|";
print OUTFILE"$aj1[$i]|";
print OUTFILE"$aj2[$i]|";
print OUTFILE"$aj3[$i]|";
print OUTFILE"$aj4[$i]\n";
}
}
}
if ($j==0)
{
for(my $k=0;$k<=$arr_size;$k++)
{
my $countr=$aj2[$k];
if($add=~m/$countr/ && $j!=1)
{
$j=$j+1;
print OUTFILE"$lines|";
print OUTFILE"|";
print OUTFILE"$aj2[$k]|";
print OUTFILE"0|";
print OUTFILE"0\n";
}
}
}
}
close(INFILE2);
close(OUTFILE);
exit;
Now what I want in the output file is that it should take the first line of the address file , print it like that and wherever it finds the matching city and country from the city_lan.txt file it shud print it afterwards sumwhat like this:
1.1.2|1. Giorgio Brajnik 2. Marji Lines |1. Dipartimento di Matematica e InformaticaUniversità di Udine Udine Italy Italy 2. Dipartimento di Scienze StatisticheUniversità di Udine Udine Italy 33100 Italy |Udine|Italy|78|87
The problem is when i am printing $lines of input file 2 it is terminating at 2.3.3 and giving an error like this:
Quantifier follows nothing in regex; marked by <-- HERE in m/? <-- HERE stanbul / at "filename" line 39, <INFILE2> line 46, why am i not able to read the whole data .what is the problem..can sumbody help??