I have a bunch of files that contain paragraphs of text and two pieces out of each paragraph of text I want to print out as a single line.. seems easy enough.. but I'm missing something fundamental I think. sample file output:
Pseudo name=hdiskpower97 Symmetrix ID=000187751303 Logical device ID=0380 state=alive; policy=SymmOpt; priority=0; queued-IOs=0 ====================================================================== +======== ---------------- Host --------------- - Stor - -- I/O Path - -- S +tats --- ### HW Path I/O Paths Interf. Mode State Q-IO +s Errors ====================================================================== +======== 0 fscsi0 hdisk100 FA 10cA active alive +0 0 2 fscsi2 hdisk254 FA 7cA active alive +0 0 Pseudo name=hdiskpower90 Symmetrix ID=000187751303 Logical device ID=0381 state=alive; policy=SymmOpt; priority=0; queued-IOs=0 ====================================================================== +======== ---------------- Host --------------- - Stor - -- I/O Path - -- S +tats --- ### HW Path I/O Paths Interf. Mode State Q-IO +s Errors ====================================================================== +======== 2 fscsi2 hdisk247 FA 7cA active alive +0 0 0 fscsi0 hdisk93 FA 10cA active alive +0 0
now, the code I've written thus far:
#!/usr/bin/perl -w use strict; use warnings; my @filelist = <usc*.devs>; foreach my $file (@filelist) { open(FH,$file) or die "cant open $file: $!"; while(<FH>) { if(/^.*Pseudo.*?\=(.*?$)/ .. /^.*Logical.*?\=(.{4})/sg) { print "$1,$2\n; } } close(FH); }
ok, so i'd expect it to fill $1 and $2 up with my groupings and print out just those two fields but $2 is unitialized and if I just print $1 it seems to be going back and forth between my groupings.. clearly I'm missing something basic about how this works. any advice?

In reply to help printing items across multiple lines by exsnafu

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.