Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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 }


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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (10)
As of 2018-02-20 16:21 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (272 votes). Check out past polls.