On Tue, 2003-12-30 at 10:04, Dan Muey wrote: > > ok with that can I still continue through the loop and > process the next line? > You can use $_ : for(qw(1 2 3)) { print "Processing files - iteration number $_\n"; my @files = qw(foo.txt bar.html); for(@files) { open(FH,"<$_") or die "Can not open $_ : $!; my $prev; while(FH) { print "Previous item was $prev\n" if defined $prev; print "Current item is $_\n"; $prev = $_; } close(FH); } } What happens when you do something like that? > will I not loose the second line now? > > On Tue, 2003-12-30 at 09:49, Dan Muey wrote: > > The lines will always be defined but I need to process that > > previous line. I am still kinda in the closet on what you mean. > > > > He means the variable $last he used. I've tried to do an > exqample that may help clear it up for you: > > my $prev; > for(qw(a b c d e f g)) { > print "Previous item was $prev\n" if defined $prev; > print "Current item is $_\n"; > $prev = $_; > } > > HTH > > DMuey > > > .. > > On Tue, 2003-12-30 at 09:42, James Edward Gray II wrote: > > On Dec 30, 2003, at 10:36 AM, Eric Walker wrote: > > > > > I am going through a file and when I enter a certain > > routine, I am > > > entering a while loop with the <IN> construct. Is > > there a way to back > > > the counter up or back up one line before I go into the > > while loop? > > > > > > a > > > b > > > c > > > d > > > > > > Instead of seeing b when I enter the while loop, adjust > > some option and > > > see the a. > > > > How about adding: > > > > my $last; > > while (<IN>) { > > # use $last here, but watch for undef on the first > > iteration, for > > example: > > do_something( $last ) if defined $last; > > > > $last = $_; > > } > > > > Hope that helps. > > > > James > > > > > > > > > > > > -- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > <http://learn.perl.org/> <http://learn.perl.org/first-response> > > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > <http://learn.perl.org/> <http://learn.perl.org/first-response> > > > > > > Sorry for the Top post its my default reply setting. Np. Ok I kinda of see what you guys/girls are talking about. Let me try something and if it doesn't work I will post up some code.
Thanks Knucklehead -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>