Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re^2: Multiple line records from a command string

by spq (Friar)
on Feb 23, 2010 at 15:40 UTC ( #824878=note: print w/ replies, xml ) Need Help??

in reply to Re: Multiple line records from a command string
in thread Multiple line records from a command string

You could also break this up a bit and handle the input per record the way you would like. Personally I also find this a little easier to read and maintain. The key from above is setting the input line separator:

$/ = "\nS"; # or $/ = "Symmetrix ID:\n"

Which will allow you to open the command output to a filehandle and use a while loop, where each iteration is an individual record. You can then easily parse out the information you want:

open(FH,"-|", "symdev list -v") or die $!; while (<FH>) { my $symm_id = my $others = undef; # or ''; if ( m/Symmetrix ID/ ) { $symm_id = ( m/Symmetrix ID\s+:\s+(\d+)/ ); } # etc }


Comment on Re^2: Multiple line records from a command string
Select or Download Code
Replies are listed 'Best First'.
Re^3: Multiple line records from a command string
by BrowserUk (Pope) on Feb 23, 2010 at 16:02 UTC

    You're obviously welcome to your view, but I cannot see the purpose in making it so complicated (20+ lines instead of 7).

    Or so needlessly inefficient. Calling the regex engine 8 times (twice each for every thing you want to match), rather than once.

    And there is absolutely no reason to initialise my vars to undef.

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://824878]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2016-02-11 02:35 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (358 votes), past polls