[Israel.pm] Double Array

Georges EL OJAIMI g-ojaimi at cyberia.net.lb
Tue Feb 8 15:06:36 PST 2005


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!!!

BR
Georges

Shlomi Fish wrote:

> On Tuesday 08 February 2005 10:34, Georges EL OJAIMI wrote:
> > Hello,
> >
> > I have a long file where in each line, 4 columns are separated by ";;;;"
> >
> > i.e.
> > C1;;;;C2;;;;C3;;;;C4
> > D1;;;;D2;;;;D3;;;;D4
> > D5;;;;D6;;;;D7;;;;D8
> > .
> > .
> > .
> > .
> > G1;;;;G2;;;;G3;;;;G4
> >
> > I have extracted the data but how can I list them in an array to be used
> > later:
> >
> >  @all = split(/\n/);
> >  foreach $line (@all) {
> >   @all1 = split(/;;;;/);
> >    foreach $line1 (@all1) {
> >    print $line1."\n";
> >    }
> >   }
> >
>
> Use array references for the internal arrays:
>
> my @lines = map { [ split(/;;;;/, $_) ] } split (/\n/, $filetext);
>
> Read perlref, perlreftut, perldsc, perllol for more information.
>
> And possibly this (instead or as well):
>
> http://vipe.technion.ac.il/~shlomif/lecture/Perl/Newbies/lecture2/references/
>
> Regards,
>
>         Shlomi Fish
>
> ---------------------------------------------------------------------
> Shlomi Fish      shlomif at iglu.org.il
> Homepage:        http://www.shlomifish.org/
>
> Knuth is not God! It took him two days to build the Roman Empire.
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://perl.org.il/mailman/listinfo/perl




More information about the Perl mailing list