Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: Why doesn't this die with "Can't use an undefined value as an ARRAY reference"?"

by kikuchiyo (Hermit)
on Oct 19, 2017 at 13:50 UTC ( [id://1201678]=note: print w/replies, xml ) Need Help??


in reply to Re: Why doesn't this die with "Can't use an undefined value as an ARRAY reference"?"
in thread Why doesn't this die with "Can't use an undefined value as an ARRAY reference"?"

One more thing I've just noticed:

The perldelta fragment mentions for(scalar($#foo)) { ... }. But what does this even mean? Why would anybody do this? $#foo is already a scalar (the index of the last element of @foo), why would anybody call scalar on it, and why would anybody use it in a foreach?

If you want to enlarge or shrink the array via $#foo, you can do it simply by $#foo = 43;. This foreach nonsense is just obfuscation and I don't see why was it "corrected".

Replies are listed 'Best First'.
Re^3: Why doesn't this die with "Can't use an undefined value as an ARRAY reference"?"
by haukex (Archbishop) on Oct 19, 2017 at 16:01 UTC
    But what does this even mean? Why would anybody do this?

    I would guess that it is maybe just a simplification of a different case; using for as a topicalizer can be pretty useful. Clicking through the commits seems to show that the change to scalar was a bugfix resulting from the discussion in #24346. I found that an enlightening point was: "Since scalar is just a directive to change context, I don't see why it should change *anything* else."

    In general, I think what this boils down to is a problem caused by autovivification, which, while of course powerful and nice, is also sometimes the source for such confusion. There is of course no autovivification; from CPAN, but personally I like to just be explicit and use exists and friends to avoid things vivifying when I don't want them to.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1201678]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-03-29 12:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found