Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^5: What does my @x= (undef)x7; do?

by BrowserUk (Patriarch)
on Nov 10, 2015 at 04:55 UTC ( [id://1147331]=note: print w/replies, xml ) Need Help??


in reply to Re^4: What does my @x= (undef)x7; do?
in thread What does my @x= (undef)x7; do?

You do realise that you aren't passing the array into modify()? You're passing a list. And that list is being aliased.

And prior to the mostly pointless, blanket constanisation of the Perl sources, the (incorrect) attribution of a null C pointer to a scalar would not have been spuriously attributed to a "read-only value".

Two mistakes collide here:

  1. The lazy definition of an api that takes a list of pre-existing and defined variables as input in order to provide output.
  2. The retroactive application of const'ing at the C-level with callous disregard to the affects at the Perl level.

Upshot: p5p have buggered Perl5 in their attempts to 'be correct'.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^6: What does my @x= (undef)x7; do?
by betterworld (Curate) on Nov 10, 2015 at 09:04 UTC
    You do realise that you aren't passing the array into modify()? You're passing a list. And that list is being aliased.

    Yes I do :) It's a list of aliases, just like in the subroutine GetVolumeInformation from the original post.

    p5p have buggered Perl5 in their attempts to 'be correct'.

    I think this is related to some optimization. Some people like to use $#array = ... because it is faster than explicitly filling the array. However this optimization comes with a cost.

    Assigning to the length does not put any SVs into the new elements, and this is why you cannot create references or aliases to them. I thought there was something about this in the documentation, but I cannot find it any more (only a related section in perlguts)

      I think this is related to some optimization. Some people like to use $#array = ... because it is faster than explicitly filling the array.

      Oh those naughty "some people"; using a defined language feature in the way it was designed.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
      In the absence of evidence, opinion is indistinguishable from prejudice.
Re^6: What does my @x= (undef)x7; do?
by AnomalousMonk (Archbishop) on Nov 10, 2015 at 17:46 UTC

    I would be very interested in any comments you might have on the, to me, very puzzling behavior seen when iterating over the aliased  @_ argument list with arrays  @b and  @c in the  modify() function in the reply above. I have only been able to confirm this behavior in the older Perl versions noted therein.


    Give a man a fish:  <%-{-{-{-<

      I assume the main point of confusion is the last case where only one of the elements get modified?


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
      In the absence of evidence, opinion is indistinguishable from prejudice.

        You assume too little confusion — always a mistake. Why, in the case of the  @b array, would nothing be changed in the aliased  @_ list? Each case more confusing than the other.


        Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-04-24 08:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found