OK, I saw your example and noted it. I intended on using next time as I know there will be:) But now I am convinced, as the lack of error checking in my script worries me. I'll take yours and fit it in!
I do need to read up on what you're doing as I am not clear on its syntax in this email. I am using this: if ($#ARGV != 1) { print "usage: ConvertASCII.pl \"input file name\" \"output file name\"\n"; exit; } open (FILEIN, "< $ARGV[0]") or die $!; my @lines = <FILEIN>; open (FILEOUT, "> $ARGV[1]") or die $!; So using your syntax escapes me at the moment:) Thanks! jlc -----Original Message----- From: Rob Dixon [mailto:[EMAIL PROTECTED] Sent: Friday, July 13, 2007 7:09 PM To: beginners@perl.org Cc: Joseph L. Casale Subject: Re: Search and Replace 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? It's also worth pointing out that Paul originally loaded the file data into an array so that he could use it twice in two successive loops. Unless the amount of your data is tiny it's much better to remove the array @lines and write this loop as while (<DATA>) { : } which reads the file one line at a time and doesn't need to draw it all into memory at once. Cheers, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/