Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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 }

HTH!


Comment on Re^2: Multiple line records from a command string
Select or Download Code
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2014-09-21 07:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (167 votes), past polls