in reply to n00b reading info from file

You'll probably get a few other examples but this is one way to do it:

p.s. This does assume you're splitting on spaces in your data file. If not, change the value in split to whatever is seperating your data.

#!/usr/bin/perl -w use strict; my @x; # your x values my @y; # your y values open FH, 'your file'; # whatever your data file is while (my $line = <FH>){ my @z = split ' ', $line; # split on space to get # your values in an array push(@x ,unshift @z); # take first element of z and # add it to x push(@y,$_) foreach(@z); # add the rest to y } close FH;

That may not be the cleanest way but to do what you want to do, the push and pop do work. After you have your values seperated, it should be trivial for you to work out the max values for each.

Good luck!

Some people fall from grace. I prefer a running start...

Update:

Aristotle was kind enough to point out I had misread the question slightly. Below is an updated version that's about as easy as I can do.

#!/usr/bin/perl -w use strict; my @x; # your x values my @y1; # your y values my @y2; my @y3; my @y4; die unless open FH, 'file.txt'; # whatever your data file # is my $count=0; while (my $line = <FH>){ ($x[$count], $y1[$count], $y2[$count], $y3[$count], $y4[$count]) = split ' ', $line; # split on space to get # your values in an array $count++; } close FH; print "X:@x\n1:@y1\n2:@y2\n3:@y3\n4:@y4\n";

Please ignore the top code unless you need to get a list of numbers in to two arrays with the first array holding the first number and the second the rest of the numbers for your file. : )

Replies are listed 'Best First'.
Re^2: n00b reading info from file
by Aristotle (Chancellor) on Jul 03, 2002 at 19:45 UTC

    Something you may want to pay attention to: you didn't check your open for success. Make it a habit:

    open FH, "<$filename" or die "can't open $filename: $!"; Also, skip the open business entirely (and process as many files as you want or if none given optionally take input from STDIN) by simply using <> to read: while (my $line = <>){ Lastly.. note that the author wanted the four y values in separate arrays..

    Makeshifts last the longest.

      Ah, you're right about the number of arrays. I guess I just read it wrong.

      As far as the solution, I agree, it's wise to check for open success. I just sort of did that on the fly to nudge the person towards their goal.

      Some people fall from grace. I prefer a running start...