Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^7: Pointers and References

by AnomalousMonk (Archbishop)
on Nov 24, 2020 at 20:13 UTC ( [id://11124158]=note: print w/replies, xml ) Need Help??


in reply to Re^6: Pointers and References
in thread Pointers and References

... you can't modify a list item in say a foreach loop ... but in the parameter list to a sub you can: $_[0] = 12 ...

Further to LanX's reply:   And, of course, one cannot modify a literal value in an argument list even though the list is passed as an array (of aliases). In no case can one modify a literal value: 1 is, let us fervently hope, always 1.

Win8 Strawberry 5.8.9.5 (32) Tue 11/24/2020 14:56:16 C:\@Work\Perl\monks >perl -Mstrict -Mwarnings -l sub f { return $_[0] = 42; } my $x = 88; print f($x); print $x; print f(99); ^Z 42 42 Modification of a read-only value attempted at - line 1.


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

Replies are listed 'Best First'.
Re^8: Pointers and References
by Leudwinus (Scribe) on Nov 25, 2020 at 15:37 UTC

    Thank you for providing your examples demonstrating how variables, but not literals, can be modified in a list via a for loop or subroutine.

Re^8: Pointers and References
by bliako (Monsignor) on Nov 24, 2020 at 20:44 UTC

    f(99) ok that's reasonable.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-04-23 12:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found