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 (Abbot) on Nov 24, 2020 at 20:44 UTC

    f(99) ok that's reasonable.