Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: Abusing Map

by Eily (Monsignor)
on May 17, 2018 at 16:16 UTC ( [id://1214756]=note: print w/replies, xml ) Need Help??


in reply to Re: Abusing Map
in thread Abusing Map

Doesn't that rely on undefined behaviour though? Auto increment and Auto decrement:

Note that just as in C, Perl doesn't define when the variable is incremented or decremented. You just know it will be done sometime before or after the value is returned.
ie: the doc doesn't rule out your code being interpreted as eval { --$i; $b[ $i ] = $a[ $i ] + $a[ $i ] } while $i;

For example: $b[ $i ] = [ $i, --$i ] while $i; builds a list of identical pairs.</c>

Correct and efficient might be:

$#b = $#a-1; # Allocate a big enough array $i = @b; $b[ $i ] = $a[ $i ] - $a[ $i+1 ] while $i--;

Replies are listed 'Best First'.
Re^3: Abusing Map
by BrowserUk (Patriarch) on May 17, 2018 at 16:40 UTC
    Doesn't that rely on undefined behaviour though? ... ie: the doc doesn't rule out your code being interpreted as ...

    Yep. And in 16 years, the behaviour, 'defined by the implementation', hasn't changed; and in the remotely possible circumstance it does, I'll fix it then.

    (Assuming any of my code ever gets run on anything newer than 5.16; and then probably by moving it to Julia.)


    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". The enemy of (IT) success is complexity.
    In the absence of evidence, opinion is indistinguishable from prejudice. Suck that fhit
    div class=

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (1)
As of 2024-04-24 14:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found