in reply to Re: Changing each item in an array
in thread Changing each item in an array

diotalevi,
I know that this was probably a contrived example by the Anonymous Monk to illustrate the problem, but in this case I would probably:
for my $item ($one, $two, $three) { $item = $item ? 'yes' : 'no'; }
This gets rid of the array all together and the need to dereference. I realize that the for loop is magically creating the reference and doing the dereference implicitly aliasing for you, but it is transparent. Hmmm - may I should get rid of that ternary operator if my point was for simplicity/clarity to the Anonymous Monk - nah!

Cheers - L~R
updated: Modified verbiage per diotalevi's clarification

Replies are listed 'Best First'.
Re: Re: Re: Changing each item in an array
by diotalevi (Canon) on Jul 19, 2003 at 00:12 UTC

    No, foreach doesn't create a reference and dereference for you. Really. Its an internals thing and it *aliases* the loop variable. This is really outside the bounds of what I think will confuse the original poster though. I also would normally have used ternary assignment but, again, in the interests of speaking to the original poster's knowledge level I kept the same if/else syntax and just changed the bits that needed to be.