Well, you might need to think a little harder -- or read our replies more carefully... But, okay, here is a working script based on what you've posted, putting together some sample data from your earlier post, and adding some other things that you haven't included yet, like assigning data to @text. (I removed "$CourseTitle", but if you really need it, I hope you can figure out how to fit it in with this approach.) Essentially, I'm providing the thing that GrandFather asked for (except that this version does not get the run-time error that you get, so it doesn't "demonstrate the problem"):
(update: the "last" condition in loop had been like the OP code ("if..."), but I think using "unless" makes more sense here -- this way, either variable being empty will exit the loop.)use strict; use Data::Dumper; my @text = <DATA>; my @courselist; my $LastCourseNumber; for (@text) { my ( $Institution, $CourseNumber, $Professor, $Enrollment ) = spli +t /\|/; last unless ( $CourseNumber && $Institution); if ($CourseNumber ne $LastCourseNumber) { push @courselist, [ $Institution, $CourseNumber, $Professor, $Enrollment]; $LastCourseNumber = $CourseNumber; } } print Dumper( \@courselist ); @courselist = sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @co +urselist; print Dumper( \@courselist ); __DATA__ UM|CS 34|Somebody|3 AC|PHIL 13|Another Person|8 UM|BIO 567|Someone Else|20
This does what you want to do (sort the array). I expect there's still more stuff in your own script that you need to fold in, and maybe when that other stuff is included, you'll still get an error. If so, that means the problem is still somewhere in the code that you have not shown us.
In reply to Re^2: How to fix error: Modification of a read-only value
by graff
in thread How to fix error: Modification of a read-only value
by Gnat53
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |