in reply to n00b reading info from file
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 | |
by Popcorn Dave (Abbot) on Jul 03, 2002 at 22:00 UTC |