Monks,

I've run some jobs that print out statistics about memory usage during their life. I use "grep" to collect relevant data into a single file. I parse that file with Perl to pull out the data that I want and create a comma-separated-values file that I can operate on with a spreadsheet tool.

Each line of the output file contains one of the data elements I want to collect. There is lots of other data that I don't want. The input data looks like this:

... Pass #123 ... ... Elapsed Time : 1753.2 sec CPU Time : 753.2 sec ... Virtual memory size : 4472.6 MB Resident set size : 4362 MB ... Major page faults : 7153 ... Pass #124 ... ...

From this data, I expect to create a line like this:

... 123, 1753.2, 753.2, 4472.6, 4362, 7153 ...

As you can see, it's sortof taking the original source data and turning it sideways, stripping off the descriptive and unwanted text. The position in the line tells me that.

My working solution is below. I just think that since "tmtowtdi", that "tMBABwtdi. I'd love to see your thoughts on what surely must be a very common task.

Thanks!

use strict; use warnings; sub slurp { local $/ = undef; local *file; open file, $_[0] or die "Can't open $_[0]: $!"; my $slurp = <file>; close file or die "Can't close $_[0]: $!"; $slurp; } my $indata = slurp('noa.txt'); print "pass, wall time (sec), CPU time (sec), VM (MB), ResMem (MB), Pa +ge Faults\n"; while ($indata =~ m/^Pass\s\#(\d+).*? ^Elapsed\ Time\s+:\s+([\d\.]+).*? ^CPU\ Time\s+:\s+([\d\.]+).*? ^Virtual\ memory\ size\s+:\s+([\d\.]+).*? ^Resident\ set\ size\s+:\s+([\d\.]+).*? ^Major\ page\ faults\s+:\s+([\d\.]+) /msgcx) { print "$1, $2, $3, $4, $5, $6\n"; }

In reply to Multiline RegExp. A Better Way? by shoness

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.