in reply to n00b reading info from file
You can do two things: either the approach you already mentioned, using five arrays, and maybe that's what you really want. Alternatively however, an array of arrays would probably a be better solution.
Using five arrays:But, probably much better, using an array of arrays:#!/usr/bin/perl -w use strict; my (@x,@y1,@y2,@y3,@y4); while(<>) { # reads a line into $_ chomp; # remove the newline from its end my @val = split; # with no parameters, split() splits $_ on whites +pace push @x, # push() to append to the end of @x shift @val; # shift pulls the first element out of an array push @y1, shift @val; push @y2, shift @val; push @y3, shift @val; push @y4, shift @val; }
or even chomp, push @val, [ split ] while <>; as the last part. Then you can later access the elements with something like print $val[3]->[0]; to see the x value of the 4th line. To see how it all works, have a look into the perllol (lol = list of lists) and the perlreftut documentation.#!/usr/bin/perl -w use strict; my @val; while(<>) { chomp; push @val, [ split ]; }
Makeshifts last the longest.
|
|---|