This is still not a piece of code that I can run on my machine and see your problem. Distil your code down to a stand alone sample that exhibits the problem. There are too many unknowns in the code you have provided. I say again, read I know what I mean. Why don't you?.
Note that your regex is probably much better done as a split:
my ($Institution, $CourseNumber, $Professor, $Enrollment) = split '|', + $try;
Oh, hold on a moment, my esp cells are kicking in. Here is the sample you should have posted:
use warnings; use strict; my @courselist; my @text = 'UM|CS 34|Smith|34'; my $courseindex = 0; foreach my $try (@text){ my ($Institution, $CourseNumber, $Professor, $Enrollment) = split +'|', $try; $courseindex = $courseindex + 1; $courselist[$courseindex] = [$Institution, $CourseNumber, $Professor, $Enrollment]; }; @courselist = sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1]} @cou +rselist;
And the answer is that you preincrement $courseindex so the first element is placed at index 1, but Perl generally starts arrays at 0 and trying to dereference aan undefined value in the sort (element 0) is generating your error.
Your code would be better written as:
use warnings; use strict; my @courselist; my @text = 'UM|CS 34|Smith|34'; foreach my $try (@text){ my ($Institution, $CourseNumber, $Professor, $Enrollment) = split +'|', $try; push @courselist, [$Institution, $CourseNumber, $Professor, $Enrol +lment]; }; @courselist = sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1]} @cou +rselist;
In reply to Re^2: How to fix error: Modification of a read-only value
by GrandFather
in thread How to fix error: Modification of a read-only value
by Gnat53
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |