Saturday, March 1, 2008

Multidimensional array in perl

I have several arrays from results of reading and parsing each line from the input. Since Perl doesn't really have a multidimensional array, I need to find out the trick to handle this problem.

Found the page below after digging on google:
http://www.unix.org.ua/orelly/perl/prog3/ch09_01.htm

Then I test it with simple code, as below:


#!/usr/bin/perl
# to test reading a file, split it, then put it into array

use strict;
use warnings;

my $ref_line;
my @lines;

open FH,"testfile.txt";
while () {
push @lines, [split(" ",$_)];
}

for $ref_line (@lines) {
print "@$ref_line[7]\n";
}

The result looks OK to me. Now it's the time to write the code into my project.

No comments: