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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.