i want to read a file1 that containfor every word a numeric reprsentation, for example:
clinton 279
capital 553
fond|fonds 1410
I read a second file, every time i find a number i replace it with the corresponding word. above an example of second file
279 695 696 152 - 574
553 95 74 96 - 444
1410 74 95 96 - 447
The problem in my code is that it execute the subroutine only one time. and it only show:
279 clinton
normally in this example it should show 3 words, when i add print $b; in the subrtoutine it show the different numbers.
#!/usr/bin/perl
use stricrt;
use warnings;
use autodie;
my @a,my $i,my $k;
my $j;
my $fich_in = "C:\\charm\\ats\\4.con";
my $fich_nom = "C:\\charm\\ats\\ats_dict.txt";
open(FICH1, "<$fich_in")|| die "Problème d'ouverture : $!";
open my $fh, '<', $fich_nom;
#here i put the file into a table
while (<FICH1>) {
my $ligne=$_;
chomp $ligne;
my @numb=split(/-/,$ligne);
my $b=$numb[0];
$k=$#uniq+1;
print "$b\n";
my_handle($fh,$b);
}
sub my_handle {
my ($handle,$b) = @_;
my $content = '';
#print "$b\n";
## or line wise
while (my $line = <$handle>){
my @liste2=split(/\s/,$line);
if($liste2[1]==$b){
$i=$liste2[0];
print "$b $i";}
}
return $i;
}
close $fh;
close(FIC1);
use strictanduse warningsin code that you post on SO (and also when you try to run it on your machine, obviously).strictorwarnings, but you haveautodie. Still, you havedieon one of youropens. You are using a lexical filehandle with 3-argument-open for one file, and a glob and 2-arg-open for the other, and oneclosehas parens while the other does not. I think you added some of the glue in between yourself, because you have@a[$i], whichstrictwould have complained about as the sigil is wrong. It should be$a[$i]because what is inside of the array@ain position$iis scalar, not an array. ...$bis reserved and should not be used as it is intended for use inside of asortblock. However, we can try to solve your question. But first, please indent it properly. You can edit the question. Then explain how it is supposed to work, as this code is not doing what you describe in the question. Also, please add at least one more line for the lookup file, and an example of the second input file.