RE: $_

From: Dan Muey (dmuey_at_infiniplex.com)
Date: 12/30/03


Date: Tue, 30 Dec 2003 10:49:44 -0600
To: <beginners@perl.org>


> 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: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Relevant Pages

  • Re: $_
    ... I am still kinda in the closet on what you mean. ... On Tue, 2003-12-30 at 09:42, James Edward Gray II wrote: ... > the counter up or back up one line before I go into the while loop? ...
    (perl.beginners)
  • Re: $_
    ... On Dec 30, 2003, at 10:45 AM, Eric Walker wrote: ... I am still kinda in the closet on what you mean. ... James ...
    (perl.beginners)
  • Re: Speaking of flutes
    ... kinda like that morbid curiosity that makes you look at the gruesome ... I found some snacks for you and hid them in your closet. ...
    (rec.games.computer.ultima.dragons)
  • Re: Displaying a large amount of data quickly (VB6)
    ... Tom Bates wrote: ... > It kinda looks like my suspicion might be correct - that anything ... > involving a loop of VB code would be too slow. ...
    (microsoft.public.vb.controls)
  • Re: declaring ignore inside a loop using destructuring
    ...   (loop for (a b c) in some-list ... throw a (declare (ignore b)) in there. ... It's kinda weird: ...
    (comp.lang.lisp)