The propose of the script to grep some value from some data table in the ASCII files.
I modified the script which I posted yesterday. Now it barely works. I wonder if it is the proper way to move a file handle in this way.
The usage is still the same
myscript.pl targetfolder/*> result.csv
F
is my file handle.
The argument I passed to the subroutine is the scalar $_
, which is used by the if
condition. When I want to move downward in my subroutine next if 1..4
will not work, so I repeat $a = <F>;
a few times to achieve moving file handle downward.
But I think this is not a proper way to move the same file handle both in my main code and my subroutine. I am not sure it will really go through every line. I need your advice.
myscript.pl
#Report strip
use warnings;
use strict;
##Print the title
Tfms2();
##Print the title
print "\n";
@ff = <@ARGV>;
foreach $ff ( @ff ) {
open (F, $ff);
@fswf = @fschuck = @fsxpos = @fsypos = @fsdev = @csnom = "";
@cswf = @cschuck = @csxpos = @csypos = @csnom = ""; # is there an efficient way?
while (<F>) {
Mfms2();
Mfms3();
}
$r = 1;
while ( $r <= $#fswf ) { # because @fsws is the largest array
Cfms3();
print "\n";
$r++;
}
close (F);
}
##==========================================================================================
##Subs
##==========================================================================================
##FS II
sub Tfms2 {
print "FS_Wafer,FS_ChuckID,FS_pos_X,FS_pos_Y,FS_deviation,CS_Wafer,CS_ChuckID,CS_pos_X,CS_pos_Y,CS_NofWafer_Ident_Spot";
}
sub Mfms2 {
if ( /^F\sM\sSTATISTICS\sII$/ ) {
$a = (<F>);
$a = (<F>);
$a = (<F>);
$a = (<F>);
$a = (<F>);
$a = (<F>);
$a = (<F>);
$a = (<F>);
$r = 1;
@b = "";
while ( $a !~ /\+\-/ ) {
chomp $a;
@b = split / *\| */, $a;
$fswf[$r] = $b[1];
$fschuck[$r] = $b[2];
$fsxpos[$r] = $b[3];
$fsypos[$r] = $b[4];
$fsdev[$r] = $b[5];
$r++;
$a = (<F>);
@b = "";
}
}
}
##FS III
sub Mfms3 {
if ( /^F\sM\sSTATISTICS\sIII$/ ) {
$a = (<F>);
$a = (<F>);
$a = (<F>);
$a = (<F>);
$a = (<F>);
$a = (<F>);
$a = (<F>);
$a = (<F>);
$r = 1;
@b = "";
while ( $a !~ /\+\-/ ) {
chomp $a;
@b = split / *\| */, $a;
$cswf[$r] = $b[1];
$cschuck[$r] = $b[2];
$csxpos[$r] = $b[3];
$csypos[$r] = $b[4];
$csnom[$r] = $b[5];
$r++;
$a = (<F>);
@b = "";
}
}
}
sub Cfms3 {
print "$fswf[$r],$fschuck[$r],$fsxpos[$r],$fsypos[$r],$fsdev[$r],";
print "$cswf[$r],$cschuck[$r],$csxpos[$r],$csypos[$r],$csnom[$r],";
}