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 -----Original Message----- From: Gary Stainburn [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 18, 2007 10:15 AM To: beginners@perl.org Subject: Re: Extreme beginner question on reading lines from a file. On Wednesday 18 July 2007 17:08, Joseph L. Casale wrote: > Is that true? > I use while loops and they cycle through each line without me keeping > track? jlc Yeah, it's true. Why would you want to keep track? (you can BTW, look at perldoc perlvar for $.) in my code, the 1st line is written into $prev. This code will fail if there's only one line in the input file as the look would never be entered. The ($this=<MYFILE>) reads from MYFILE putting the line into $this. The whole expression then returns the result. If it's worked it returns true and the loop is executed. If it fails it returns false and the loop exits. Loosely speaking anyway Gary > > -----Original Message----- [snip] > Hi Ayesha > > you need to only read once per line, but remember the last one. > > $prev=<MYFILE> > while ($this=<MYFILE>) { > print "$prev and $this\n"; > $prev=$this; > } > -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/