Hey guys, I'm stuck with a sorting question. I keep getting the answer "Modification of a read-only value" at the sort. extract is a subroutine that extracts information from a file, and that is where the variables are defined ($name, etc.). I have successfully sorted things in the past, and have read (well, tried) a lot of things about this kind of error, but I am just not understanding the concept. The array prints out fine for me before and after the foreach loop, and I can't see any gaps in the information that would screw up a sort function. I am not defining anything in the extract subroutine as an array; everything is just a single variable. I've tried using strict and warnings and they didn't help with this problem. (should have used them from the beginning, but I didn't know how they worked and have gotten along fine without them so far). I was trying to use pop to put elements into the array, but the defining doesn't seem to be my issue here. What should I try looking at next in order to resolve this issue?

if($type eq 2){ @Files=<C:/perlscripts/Characters/*>; $v=1; foreach $file (@Files){ $A=join "",(split /\//,$file)[3]; #print "A:$A\n"; $char[$x]=join "", (split /\./,$A)[0]; $File_loc="C:\\perlscripts\\Characters\\"; $name=$char[$x]; $txt=".txt"; $FILE=$File_loc.$name.$txt; #print "$FILE\n"; open (CHAR_STATS, "$FILE")||die "Couldn't open the file, $!"; extract(CHAR_STATS); $S[$v]=[$name,$INIT,$DEX+$INIT_MISC,roll("1d20")]; print ".$v.\t.$S[$v][0].\t.$S[$v][1].\t.$S[$v][2].\t.$S[$v][3].\n"; $v++; } #pop(@S); print ".........\n"; $v--; for($y=1; $y<=$v; $y++){ print ".$v.\t.$S[$y][0].\t.$S[$y][1].\t.$S[$y][2].\t.$S[$y][3].\n"; } $a=(); $b=(); @G=sort{$a->[1] <=> $b->[1]||$a->[2] <=> $b->[2]||$a->[3] <=> $b->[3]} + @S; for (my $i=0; $i<=$#G; $i++) { print "$G[$i][0]\t$G[$i][1]\t$G[$i][2]\ +t$G[$i][3]\n"; } }

In reply to Sorting array, getting modification of read-only value error by myelinviolin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.