Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Common Causes for "Modification of a read-only value attempted"

by imp (Priest)
on Sep 01, 2006 at 02:58 UTC ( #570712=perltutorial: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    for my $x (1,2) {
      $x++;
    }
    
  2. or download this
    for (1,2) {
      chomp;
    ...
    
    @array = map  { $_++ } (1,2);
    @array = grep { $_++ } (1,2);
    
  3. or download this
    sub incr {
      $_[0]++;
    ...
    my $n = 1;
    incr($n); # good
    incr(1);  # bad
    
  4. or download this
    @array = sort { $a++ } (1,2);
    
  5. or download this
    my @bad;
    $bad[0] = [1];
    $bad[2] = [2];
    @bad = sort {$a->[0] <=> $b->[0]} @bad;
    
  6. or download this
    for (1,2) {
      my $data = prompt_user();
    ...
         # Do stuff
       }
    }
    
  7. or download this
    for (1,2) {
        while (<STDIN>) {
        }
    }
    
  8. or download this
    $_++ for (1,2);
    $_++ for (1,@array);
    @array = map {$_++} (1,@array);
    
  9. or download this
    my @array = (1,2);
    for (@array) {
      $_++;
    }
    
  10. or download this
    my ($x,$y) = (1,2);
    for ($x,$y) {
      $_++;
    }
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (14)
As of 2015-07-28 19:11 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 (258 votes), past polls