Whoops.

OK, so DataDumper revealed that my script is in fact producing an array full of empty references and I've evidently confused myself more than I thought...consequently I have a new question.

I have a file that looks like this:

7 1 2 20 2 3 15 3 4 3 4 5 17 5 6 28 6 1 23 1 7 1 2 7 4 3 7 9 4 7 16 5 7 25 6 7 36 -1

What I would like to do is take all the lines that are not the first or last line and make a sortable multidimensional array out of them, as described above.

My current code is:

#!/usr/bin/perl use warnings; use strict; use Data::Dumper; #open initial file open FILE, "graph.txt" or die "Error with original file: $!"; #open empty file to write to #open NEWFILE, ">output.txt" or die "Error with output file: $!"; #Get array with lines of file my @line_array = <FILE>; #reduce array to content info only shift(@line_array); pop(@line_array); #initialize item array and something to hold it during loop our @item_array; our @hold_array; #convert each edge string to an array, push it onto item_array for (my $i = 0; $i < scalar(@line_array); $i++) { our $line = $line_array[$i]; @hold_array = split(/\s/, $line); push(@item_array, \@hold_array); } print Dumper @item_array;

This produces in Dumper:

$VAR1 = [ '6', '7', '36' ]; $VAR2 = $VAR1; $VAR3 = $VAR1; $VAR4 = $VAR1; $VAR5 = $VAR1; $VAR6 = $VAR1; $VAR7 = $VAR1; $VAR8 = $VAR1; $VAR9 = $VAR1; $VAR10 = $VAR1; $VAR11 = $VAR1; $VAR12 = $VAR1;

Pretty sure this isn't what I want...am I approaching this the wrong way?

Thank you both for your help, by the way...you're awesome! =)


In reply to Re: Sort multidimensional array by third item by rosalindwills
in thread Sort multidimensional array by third item by rosalindwills

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.