[Israel.pm] Double Array

Shlomo Yona shlomo at cs.haifa.ac.il
Tue Feb 8 22:58:04 PST 2005


On Wed, 9 Feb 2005, Georges EL OJAIMI wrote:

> Hello,
>
> I tried the following:
>
> $datafile = "data.txt";
>
> open(FILE, "$datafile") || die "Unable to locate the path of the
> File.\n";
> while(defined($line=<FILE>)) {
> my @lines = map { [ split(/;;;;/, $_) ] } split (/\n/, $line);
> }
> close (FILE);
>
> my $len = scalar(@lines);
> print $len;
>
> It is always giving me an empty array!!!
>
> At the other hand if I try:
> 	my @lines = map { [ split(/;;;;/, $_) ] } split (/\n/, <FILE>);
> It is returning the first line only!!!

my $filename = "data.txt";
open(FILE,"<",$filename) or die "Cannot open $filename for reading: $!\n";
my @lines;
while(my $line=<FILE>) {
 	chomp $line;
 	push @lines,[split(/;{4}/,$line)];
}

# now, do something with @lines.
# @lines is a LoL.


-- 
Shlomo Yona
shlomo at cs.haifa.ac.il
http://cs.haifa.ac.il/~shlomo/



More information about the Perl mailing list