perlstudent89 has asked for the wisdom of the Perl Monks concerning the following question:
So, I am a perl newb, and am having trouble sorting a mutlidimensional array.
The data is a table, and looks like:
00000(IDR) 86480 22 41.435 40.696 40.728167 0 FRM 3
00002( P ) 35248 24 38.568 39.327 40.641 253 53 FRM 2
.
.
.
00015( B ) 9312 24 45.460 43.808 42.001 409 208 FRM 0
I read it in, line by line, parse it, and want to sort the rows in order of the first column. This is my code:
while (<FH>) { chomp $_; @line_array = split(/[()\t+\s+]/, $_); @full = map {$_ ? $_ : ()} @line_array; @{$data[$readcounter]} = @full; } @data = sort { $a->[0] <=> $b->[0] } @data;
And I get:
Modification of a read-only value attempted at...(the sort line)
What am I doing wrong? From the examples and documentation I've looked at, this is the correct way to do it, but apparently for me, its not working...
Thanks.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Read Only Error -- Sorting an Array
by NetWallah (Canon) on Sep 16, 2012 at 15:29 UTC | |
by perlstudent89 (Initiate) on Sep 16, 2012 at 17:43 UTC | |
Re: Read Only Error -- Sorting an Array
by tobyink (Canon) on Sep 16, 2012 at 15:38 UTC | |
by perlstudent89 (Initiate) on Sep 18, 2012 at 02:50 UTC | |
by tobyink (Canon) on Sep 18, 2012 at 06:56 UTC | |
by perlstudent89 (Initiate) on Sep 18, 2012 at 20:25 UTC | |
Re: Read Only Error -- Sorting an Array
by choroba (Cardinal) on Sep 16, 2012 at 15:23 UTC | |
Re: Read Only Error -- Sorting an Array
by Cristoforo (Curate) on Sep 17, 2012 at 01:29 UTC | |
by perlstudent89 (Initiate) on Sep 18, 2012 at 02:52 UTC |