Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Still don't undersand "Modification of a read-only value attempted" error

by derby (Abbot)
on Jun 20, 2012 at 22:02 UTC ( #977488=note: print w/ replies, xml ) Need Help??


in reply to Still don't undersand "Modification of a read-only value attempted" error

$item is always an alias. In the 'failing' foreach, it's an alias to a constant in a list and hence not modifiable (where would perl save the modification?) For the 'working' foreach, $item is an alias to an array element which is modifiable (since we have some place to save the modification). So either use your array or make a copy of the aliased item:

(my $val = $item) =~ s/abc/zzzzzz/;

-derby


Comment on Re: Still don't undersand "Modification of a read-only value attempted" error
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (13)
As of 2015-07-28 21:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (259 votes), past polls