The first sorted array crashes out because the data isnt split, but does return the first 0-9 elements of the array ( top 10 )...
the second sort works perfectly, but now i cant extract the first elements without an error, Please would you be so kind as to tell me where i am going wrong...
#### Old sort (that doesnt work properly ) with first 10 records extra +cted foreach my $k (keys %IND) { @indsort=(sort { $a <=> $b } @{$tmp}); foreach $line(@indsort[0..9]){ print "$line\n"; } }
So to my delight i fixed the sort on the array, but now the extraction of n elements isnt working, please see below:
#### New sort (which works!) with first 10 records NOT extracted foreach my $tmp (keys %IND) { my @lines; open(FILE, "+< tmp/$tmp.dat") or die "file:$tmp $!"; while (<FILE>) { chomp; my @line = split(','); push(@lines, \@line); } @lines = sort { $a->[0] <=> $b->[0]} @lines; foreach my $line (@lines) { print join(",", @{$line}) . "\n"; } }
gives the error:

Use of uninitialized value in array dereference...
in this line:
print join(",", @{$line}) . "\n";

In reply to first elements in array, split join and sort problem by alexiskb

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.