Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Allocation of anonymous arrays

by sundialsvc4 (Abbot)
on Feb 07, 2014 at 15:20 UTC ( #1073890=note: print w/ replies, xml ) Need Help??


in reply to Allocation of anonymous arrays

No, Perl won’t put two arrays into the same storage just because (at the moment ...) their values are identical.  But ... in practice, it sure is easy to come into a situation where you think that it did ... where you think that you’re just changing a value “over here,” and ... (gasp!) ... a value “over there” just changed, too!

What will actually turn out to have happened, in those cases, is that you had a reference to the same list of values in two or more places ... that you thought that you were telling Perl to move (to duplicate) an array or a hash (something that requires to be “referenced” ...).   But what Perl was actually doing was creating references.   It seemed to work, until you changed what you thought was an independent, isolated value, and saw that the changes had apparently propagated.   Easy to do.   And the [erroneous ...] explanation, that the optimizer did something wrong, is also an intuitively-appealing assumption.

Perl tries hard to be a “DWIM = Do What I Mean, TMTOWTDI = There’s More Than One Way To Do It™” language, and so its very-flexible syntax is occasionally misleading.   If you are used to dealing with strongly-typed and/or compiled languages where there’s really only one way to do it and where any deviations from that will be caught for you at compile time ... Perl isn’t like that.   Its design is not like that, which is neither right nor wrong.


Comment on Re: Allocation of anonymous arrays
Re^2: Allocation of anonymous arrays
by Bloodnok (Vicar) on Feb 08, 2014 at 10:56 UTC
    In fact, perl frequently has that, what we used to know when dealing with the Navy at Ferranti - Training Simulator Group as the, 'NWITIAF' (Not What I Thought I Asked For) factor :-)

    A user level that continues to overstate my experience :-))

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (14)
As of 2014-09-30 19:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (383 votes), past polls