Joseph L. Casale wrote:
One of these scripts has a loop like this:

for my $line (@lines){
 my $line2 = $line;
 $line =~ s/(\S+)\s+(\S+)\s+(\S+)/X$1 Y$2/;
 print FILEOUT $line;
 $line2 =~ s/(\S+)\s+(\S+)\s+(\S+)/Z[$3+DPad]/;
 print FILEOUT $line2;
 print FILEOUT "M98PDRILL.SUBL1\n";
 print FILEOUT "G90\n";
 print FILEOUT "G00 Z[CPlane]\n"
}

What would be a wise way of trapping a condition such as the line read
and passed into the loop is not 3 sets of numbers and if so, skip?

I'm sticking with using split() - this sort of thing is exactly what it's for!

The first 'next' statement makes sure there are exactly three data items
in the line, the second one makes sure that none of them contain anything
except the digits 0 through 9, a decimal point or a minus sign.

HTH,

Rob


foreach (@lines) {

 my @data = split;
next unless @data == 3;
 next if grep /[^0-9.-]/, @data;

 printf FILEOUT "X%s Y%s\n", $data[0], $data[1];
 printf FILEOUT "Z[%s+DPad]\n", $data[2];
 print  FILEOUT "M98PDRILL.SUBL1\n";
 print  FILEOUT "G90\n";
 print  FILEOUT "G00 Z[CPlane]\n"
}

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to