You've already got some answers to your issue - just note the issue with \@points that I discussed here, including that it's a good idea if you Use strict and warnings.

Since it looks like you're parsing CSV, I'd recommend using a module for this, in particular Text::CSV:

#!/usr/bin/env perl use warnings; use strict; use Text::CSV; my $csv = Text::CSV->new({binary=>1, auto_diag=>2}); $csv->getline(\*DATA); # read and discard header my @candidates; while ( my $row = $csv->getline(\*DATA) ) { my %student; for my $key (qw/ id gender birthday status room seat version /) { # remove the first elements of the arrayref $student{$key} = shift @$row; } # all that's left in the arrayref is the points $student{points} = $row; push @candidates, \%student; } $csv->eof or $csv->error_diag; use Data::Dump; dd \@candidates; __DATA__ ID,gender,birthdate,order,room,seat,version,points,,,,,,,,,,,,,,,,,,,, +,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 277710814533,f,01/02/1993,m,sr_3,A11,A, 1,1,1,1,0,1,1,1,.5,1,1,1,0,1,. +5,1,1,1,0,1,.5,1,1,0,1,1,1,1,1,1,1,0,0,1,0,1,.5,1,1,1,1,.5,0,1,1,1,0, +1,1,1,1,1,0,1,1,1,.5,1,1,1 755310765962,f,31/07/1992 00:00,v,aula,C11,C,1,.5,0,1,1,1,1,1,1,1,1,1, +1,1,0,1,1,1,1,1,0,1,1,1,1,0,1,1,1,.5,1,0,.5,1,0,1,.5,0,.5,0,1,0,0,.5, +1,1,0,.5,1,1,.5,.5,1,.5,.5,1,1,1,.5,.5 394610513538,m,20/10/1992 00:00,m,sr_3,E13,E,1,1,0,.5,1,1,1,1,1,1,1,.5 +,1,1,.5,.5,1,1,1,.5,.5,1,1,1,1,0,0,.5,1,1,.5,.5,.5,.5,0,1,0,.5,0,0,1, +0,1,.5,0,1,0,0,.5,1,0,1,1,0,.5,.5,.5,.5,.5,.5

Note that DATA is a special filehandle that refers to the __DATA__ section at the end of the script, but you can use any other filehandle here, like FH in your program. Although, it'd be better to switch to "lexical" filehandles, that is open my $fh, '<', $filename or die "open $filename: $!"; (see open).


In reply to Re: How to code a complex AoH? by haukex
in thread How to code a complex AoH? by iatros

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.