in reply to Re: read-only error
in thread read-only error

Another cause for the Modification of a read-only value error is using a sort block that dereferences $a and $b, and has gaps.

This is ok:

use strict; use warnings; my @list; $list[0] = 0; $list[2] = 2; @list = sort {$a <=> $b} @list;
This isn't:
use strict; use warnings; my @list; $list[0] = [0]; $list[2] = [2]; @list = sort {$$a[0] <=> $$b[0]} @list;

Replies are listed 'Best First'.
Re^3: read-only error
by ikegami (Patriarch) on Aug 24, 2006 at 19:52 UTC

    $a and $b are read-only in a sort block.

    @list = sort { $a = 1; } @list;

    You're getting the error because you are attempting to auto-vivify them.

    I hate auto-vivification, or at least that it's on by default.