Need help understanding perl script error

I solicited this site earlier this week and got a good answer for a perl
Script so I made this script from what understood from the answers
But now I have a bug and I'm stump. It doesn't parse correctly the
Output it stays on the first line My $f2 and reprints in a endless loop
I'm sure there are better ways than this. But this is what I want to solve
Dan

This is the script

 
#!/usr/local/bin/perl -w
use strict;
 
die "Usage: $0 <file1> <file2> <file_out>\n" unless $#ARGV==2;
my ($file1, $file2, $file3) = @ARGV;
 
open my $f1_in, $file1 or die "Could not open $file1\n";
open my $f2_in, $file2 or die "Could not open $file2\n";
open(my $f3_out, '>', $file3) or die "Could not open $file3: $!\n";
 
while (my $f1 = <$f1_in>) {
my $f2 = <$f2_in>;
$f1 =~ s/^\s+|\s+$//g;
$f2 =~ s/^\s+|\s+$//g;
 
#$\ = "\n";
my $FS = '|';
$, = ',';
 
my $Fld0 = shift;
my $Fld1 = shift;
my $Fld2 = shift;
my $Fld3 = shift;
my $Fld4 = shift;
my $Fld5 = shift;
my $Fld6 = shift;
my $Fld7 = shift;
my $Fld8 = shift;
my $Fld9 = shift;
my $Fld10 = shift;
 
while ($f2){
($Fld0,$Fld1,$Fld2,$Fld3,$Fld4,$Fld5,$Fld6,$Fld7,$Fld8,$Fld9,$Fld10) = split(/[|\n]/,$f2, -1);
print $f3_out ($Fld0, $Fld1, $Fld2, $Fld3, $Fld4, $Fld10);
}
}

I'm not sure what all those "shift" lines are in there for, but your loop problem is here:

while ($f2){
($Fld0,$Fld1,$Fld2,$Fld3,$Fld4,$Fld5,$Fld6,$Fld7,$Fld8,$Fld9,$Fld10) = split(/[|\n]/,$f2, -1);
print $f3_out ($Fld0, $Fld1, $Fld2, $Fld3, $Fld4, $Fld10);
}
}

You need to remove the "while" loop:

($Fld0,$Fld1,$Fld2,$Fld3,$Fld4,$Fld5,$Fld6,$Fld7,$Fld8,$Fld9,$Fld10) = split(/[|\n]/,$f2, -1);
print $f3_out ($Fld0, $Fld1, $Fld2, $Fld3, $Fld4, $Fld10);

}

I don't know if that will make your code do something useful but hopefully it will run and you can further modify as needed.

Thank you for the reply

 I do want it to loop but not endlessly on the first line of file2.

File2 has 24000 records split in 10 fields I do have it working
Now but I'm using 2 scripts to do it one extract the records the
Other matches them. What I'm trying to do is combining them
Into one

Thk

If you don't want it to loop endlessly then remove the 'while' loop I showed you to remove.

---------- Post updated at 02:25 PM ---------- Previous update was at 02:15 PM ----------

Maybe this is w2hat you want to do:

#!/usr/local/bin/perl
use warnings;
use strict;
 
die "Usage: $0 <file1> <file2> <file_out>\n" unless $#ARGV==2;
my ($file1, $file2, $file3) = @ARGV;
 
open my $f1_in, $file1 or die "Could not open $file1\n";
open my $f2_in, $file2 or die "Could not open $file2\n";
open(my $f3_out, '>', $file3) or die "Could not open $file3: $!\n";
 
while (my $f1 = <$f1_in>) {
   my $f2 = <$f2_in>;
   $f1 =~ s/^\s+|\s+$//g;
   $f2 =~ s/^\s+|\s+$//g;
 
   my($Fld0,$Fld1,$Fld2,$Fld3,$Fld4,$Fld5,$Fld6,$Fld7,$Fld8,$Fld9,$Fld10) = split(/\|/,$f2, -1);
   print $f3_out join(',',$Fld0, $Fld1, $Fld2, $Fld3, $Fld4, $Fld10);
}