in reply to Re^3: What is the difference between |= and ||=?
in thread What is the difference between |= and ||=?

It's undef because the hash reference is a value returned from an SQL query. If no rows are selected (for instance), then it's possible for the 'id' value to be undef. And when I perform some math operation (as noted by Marshall below), the warning is triggered. I could wrap the math operation code around a conditional to suppress the warning:

if ($some_href->{id}) { if ($some_href->{id} > 0) { do_something(); } }
But I'm not sure if that's better than using ||=.

Replies are listed 'Best First'.
Re^5: What is the difference between |= and ||=?
by ikegami (Patriarch) on Apr 08, 2009 at 06:11 UTC
    If no row was selected, then whose id is that? Sure smells fishy.

      The "id" was an example. But there are cases (especially when JOINS are involved) where some columns have NULL values or where rows are not yet inserted. In those instances, the particular value of the hash reference is undef.

        The "id" was an example.

        Which brings us back to my answer: It all depends on the situation. In the situation you gave, it doesn't seem right.