Hi
i am running a issue with the way i handel open file in perl
i have the following input file <File1>
D33963|BNS Default Swap|-261564.923909249|
D24484|BNS Default Swap|-53356.6868058492|
D24485|BNS Default Swap|-21180.9904679111|
D33965|BNS Default Swap|154181.478745804|
D24486|BNS Default Swap|-47413.0013193052|
D33966|BNS Default Swap|-154181.478745804|
D24487|BNS Default Swap|-63253.9807711966|
D33968|BNS Default Swap|-160521.81007754|
D24489|BNS Default Swap|-10584.4665849774|
S85801|BNS Swap|451309.300774646|
D33969|BNS Default Swap|118166.419991555|
i would like too read the full file line by line, extract the first field (ex in the first case D33963)
search for that value in an other file <file2> that king of look like this
(it is a big file with me specific order)
:E00277,48089,,,Trading,FALSE,,CAISSE,19189,AA,CAD
:D24485,48085,,,Trading,FALSE,,CASSE,19139,AA,CAD
:D2448,48083,,,Trading,FALSE,,CAIE,19029,AA,CAD
:D33963,48082,,,Trading,FALSE,,CAISSE,19149,AA,CAD,
:E00286CAP,48082,,,Trading,FALSE,,CAISSE,19149,AA,CAD
then when i find the value in <file2> i would line the full line of <file1> and full line of file2 to be merge and writen in a output file
this is the code i come with, but for some raison it look like my <file2> is read only once, and start the second search from the point where it found the previous (so forgeting the begining of the file)
#!/bin/perl
open(F1,"<@ARGV[0]");
open(F2,"@ARGV[1]");
open (OUTFILE,">$ARGV[2]");
sub run () {
while(<F1>)
{
chomp;
$line = $_;
@ARA_NAME = split(/\|/,$line);
find_ara_name()
}
close(F1);
close(F2);
}
sub find_ara_name() {
while (<F2>){
chomp;
$line1 = $_;
if ($line1 =~ m/:@ARA_NAME[0],/) {
print "found @ARA_NAME[0]\n";
$line1 =~ s/,/|/g;
print OUTFILE "$line$line1\n";
return;
}
}
}
#main
run()
this is the output i would like for every record of <file1> if no match i will later write a other output file to track those
D33963|BNS Default Swap|-261564.923909249|:D33963|48082|||Trading|FALSE||CAISSE|19149|AA|CAD|
thanks for your help in advance