Re: Accessing previous element of an array in a 'foreach' loop

2002-02-06 Thread Jenda Krynicky
From: Jeff 'japhy' Pinyan <[EMAIL PROTECTED]> > On Feb 6, Brett W. McCoy said: > > >On Wed, 6 Feb 2002, Carl Rogers wrote: > > > >> foreach(@array) { > >> > >>if ($_ =~/somecondition/) { > >># I want to do something to the element prior to $_ ($_ - 1) > >>} > >> } >

Re: Accessing previous element of an array in a 'foreach' loop

2002-02-06 Thread Brett W. McCoy
On Wed, 6 Feb 2002, Jeff 'japhy' Pinyan wrote: > Err, no. $_ is STILL an alias. > > my @words = qw( once upon a time ); > length > 1 and $_ = ucfirst($_) for @words; > print "@words"; # Once Upon a Time argh, yeah. I was thinking backwards. Thanks for pointing that out. -- Brett

Re: Accessing previous element of an array in a 'foreach' loop

2002-02-06 Thread Jeff 'japhy' Pinyan
On Feb 6, Brett W. McCoy said: >On Wed, 6 Feb 2002, Carl Rogers wrote: > >> foreach(@array) { >> >> if ($_ =~/somecondition/) { >> # I want to do something to the element prior to $_ ($_ - 1) >> } >> } > >The problem here is that $_ is a *copy* of the element in the array -- >modif

Re: Accessing previous element of an array in a 'foreach' loop

2002-02-06 Thread Brett W. McCoy
On Wed, 6 Feb 2002, Carl Rogers wrote: > Good day; > > I'm using foreach to do something to an array. is there a way I can > reference a previously 'seen' element without having to traverse the array > with a for(;;) statement? > > ie. I'd like this to work: > > foreach(@array) { > > if ($_

Re: Accessing previous element of an array in a 'foreach' loop

2002-02-06 Thread Jeff 'japhy' Pinyan
On Feb 6, Carl Rogers said: >I'm using foreach to do something to an array. is there a way I can >reference a previously 'seen' element without having to traverse the array >with a for(;;) statement? > >ie. I'd like this to work: > >foreach(@array) { > > if ($_ =~/somecondition/) { >

RE: Accessing previous element of an array in a 'foreach' loop

2002-02-06 Thread Nikola Janceski
PROTECTED] Subject: Accessing previous element of an array in a 'foreach' loop Good day; I'm using foreach to do something to an array. is there a way I can reference a previously 'seen' element without having to traverse the array with a for(;;) statement? ie. I'd like

Accessing previous element of an array in a 'foreach' loop

2002-02-06 Thread Carl Rogers
Good day; I'm using foreach to do something to an array. is there a way I can reference a previously 'seen' element without having to traverse the array with a for(;;) statement? ie. I'd like this to work: foreach(@array) { if ($_ =~/somecondition/) { # I want to do something