[Israel.pm] Double Array

Shlomi Fish shlomif at iglu.org.il
Tue Feb 8 03:40:50 PST 2005


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.



More information about the Perl mailing list