Ok. Well @table = @data[1..$height]; may not be doing what you expect.
If you are unsure about your data structures or are just curious, then you can use Data::Dumper
use Data::Dumper; $datafile = 'testdata.txt'; chomp $datafile; open (INPUT, $datafile) || die ("Unable to open $datafile"); @data = <INPUT>; close INPUT; @dim = split(/\,/, $data[0]); $width = $dim[0]; $height = $dim[1]; @table = @data[1..$height]; print Dumper(@table); die; for($row = 0; $row < $height; $row++) { for($col = 0; $col < $width; $col++) { $myString = $myString.$table[$row][$col]; } $myString =""; }
@table is not a multi-dimensional array (because of the way you tried to create it). Therefore, there is no such
$table[$row][$col]. Each element of @data is a single line of $datafile. @table = @data[1..$height]; is merely creating a new array which contains the same elements as @data.

I don't know exactly know what you are trying to do, but to get access to each byte of each element/row in @table, you can use substr(). You don't need a 2-dimensional array for that:

use strict; use warnings; my $datafile = $ARGV[0] || die "File to open was not provided!"; my @data; open (DATA_FILE, '<', $datafile) || die ("Unable to open $datafile"); @data = <DATA_FILE>; close(DATA_FILE); my @dim = split /\,/, $data[0]; my $width = $dim[0]; my $height = $dim[1]; my @table; push (@table, @data[1..$height]); my $myString =''; for(my $row = 0; $row < $height; $row++) { for(my $col = 0; $col < $width; $col++) { $myString .= substr($table[$row], $col, 1); } $myString =""; }

In reply to Re^3: 2 dimensional array by kabeldag
in thread 2 dimensional array by mountain_drew

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.