Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: Bitten by the lazy execution bug?

by mccready (Initiate)
on Dec 08, 2007 at 20:38 UTC ( [id://655880]=note: print w/replies, xml ) Need Help??


in reply to Re: Bitten by the lazy execution bug?
in thread Bitten by the lazy execution bug?

That is bizarre. I would have thought the values would have been passed in "by value".
  • Comment on Re^2: Bitten by the lazy execution bug?

Replies are listed 'Best First'.
Re^3: Bitten by the lazy execution bug?
by antirice (Priest) on Dec 09, 2007 at 06:56 UTC

    To quote from perldoc perlsub:

    The array @_ is a local array, but its elements are aliases for the actual scalar parameters. In particular, if an element $_[0] is updated, the corresponding argument is updated (or an error occurs if it is not updatable). If an argument is an array or hash element which did not exist when the function was called, that element is created only when (and if) it is modified or a reference to it is taken.

    Thus the behavior of this code:

    #!/usr/bin/perl -l my @a = 1..3; sub inc { $_++ for @_; } inc(@a); print for @a; inc('hello'); __DATA__ 2 3 4 Modification of a read-only value attempted at - line 6.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2025-12-13 19:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (93 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.