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)
> >>}
> >> }
>
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
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
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 ($_
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/) {
>
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
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