in reply to Modification of read-only value error

The error is from attempting to modify $_[0] when the argument is a string literal, $rollup->(" ") rather than a variable $rollup->($dummy). The string literal is a constant, not an lvalue.

After Compline,
Zaxo

  • Comment on Re: Modification of read-only value error when using closure

Replies are listed 'Best First'.
Re^2: Modification of read-only value error when using closure
by sk (Curate) on Aug 24, 2005 at 05:12 UTC
    Thanks Zaxo!!!

    I was under the impression that args are sent as values through @_ and thought that this problem was something to do with closures. I went back and tried a chomp on simple sub and the same happened. I checked perldoc perlsub and i got this info

    Any arguments passed in show up in the array @_. Therefore, if you ca +lled a function with two arguments, those would be stored in $_[0] an +d $_[1]. 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 occu +rs if it is not updatable).

    Now it is clear to me!

    thanks again!

    cheers

    SK