Welcome to the Monastery.
"Learning Perl" is a great book to read cover to cover, doing the tasks, reading the chapters in order. Not the best reference to pick out sections from and taking out stuff specific to the task you have at hand. There are better sources of knowledge for this type of search, a great point to start would be the Perl FAQ. Read the FAQ, try to get the bits you need, play around, break stuff, and read "Learning Perl" at your own pace. Make sure that the edition you have is at least the fourth one, and if you have the most recent one (6th edition), take everything you read in Chapter 15 (the one about the smart match operator) with a grain of salt. Some things have changed.
As to your problem, here is a small example that could get you started.
#!/usr/bin/perl use warnings; use strict; my $maxvalue; my $value_at_3k; while (my $line = <DATA>) { my ($time, $value) = split ' ', $line; if ($value > $maxvalue) { $maxvalue = $value; } unless (defined $value_at_3k) { if ($time > 3000) { $value_at_3k = $value; } } } print "Maxvalue was $maxvalue \n"; print "Value at 3k was $value_at_3k \n"; __DATA__ 2999.98 280 2999.99 281 3000.01 285 3000.02 290 3000.03 320 3000.04 350 3000.05 325 3000.06 275 3000.07 270 3000.08 260 3000.09 235
Start by reading the FAQ, then try to change the code so it reads the data from a file (with the filename declared explicitly in the code). Then wrap the code in a subroutine that accepts the filename as a parameter. Then try iterating over a directory - first printing the filenames, then passing them as arguments to your sub. Then wrap it up. Good luck with the task ahead of you.
And it's good to learn. You are very right about this.
- Luke
In reply to Re: New to Perl - locating max, subtracting initial, printing output, all across several files in differing directories
by blindluke
in thread New to Perl - locating max, subtracting initial, printing output, all across several files in differing directories
by jtrousde
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |