On 7/18/07, Joseph L. Casale <[EMAIL PROTECTED]> wrote:
Hrm,
I am confused then:)
I have this as a file I am using right now!
while (<FILEIN>) {
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 "G01 Z[%s+DPad] F[PFRate]\n", $data[2];
printf FILEOUT "[DrillZVal = %s]\n", $data[2];
print FILEOUT "M98PPECK.SUBL1\n";
print FILEOUT "G90\n";
print FILEOUT "G00 Z[CPlane]\n"
}
How come this works perfectly, it reads in each line separated 3-tuple of
coordinates and processes them perfectly? I also am just learning, so I
am not sure why I need to do more?
Thanks!
jlc
The original question was how do I get the current line and the next
line without consuming the next line (i.e. line1 and line 2, line2 and
line3, line3 and line4). You are reading one line at a time.
Gary's method works, but, this being Perl, there is more than one way to do it:
#!/usr/bin/perl
use strict;
use warnings;
while (defined (my $first = <DATA>)) {
my $pos = tell DATA;
my $second = <DATA>;
last unless defined $second;
#or this if you want to process the last line
#$second = '' unless defined $second;
seek DATA, $pos, 0;
chomp($first, $second);
print "$first :: $second\n";
}
__DATA__
line1
line2
line3
line4
line5
line6
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/