in reply to Re^2: compare values within hash
in thread compare values within hash

Using exists on array elements makes no sense.
I disagree. It seems like the documentation to which you link also disagrees:
Given an expression that specifies a hash element or array element, returns true if the specified element in the hash or array has ever been initialized, even if the corresponding value is undefined.
It clearly mentions "array"; I must be missing your point.

Here is what I was trying to accomplish. The OP has two arrays of different sizes. I decided to loop over the larger array (a1). In order to avoid a warning when checking the last element of a1 versus a non-existent element of the smaller array (a2), I decided to use exists. In my example, it Does What I Want.

Thanks for pointing out $i < @a2; I definitely prefer it to my usage of exists in this case.

Replies are listed 'Best First'.
Re^4: compare values within hash
by ikegami (Patriarch) on Nov 23, 2008 at 18:55 UTC

    It seems like the documentation to which you link also disagrees

    I didn't say it invalid. I said it was useless. You never need to know whether an SV was allocated for an array element. You either need to know if an array element is defined or if it's beyond the end of the array. exists doesn't tell us either.

    I decided to loop over the larger array (a1). In order to avoid a warning when checking the last element of a1 versus a non-existent element of the smaller array (a2), I decided to use exists.

    In addition to doing that, it skips some warnings on elements before the last element.