Here is all the code I can think is relevant.

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"):

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
(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.)

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

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.