Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Parsing output from a command

by BrowserUk (Patriarch)
on Mar 24, 2009 at 15:57 UTC ( [id://752907]=note: print w/replies, xml ) Need Help??


in reply to Parsing output from a command

By setting $/ to '', it enables 'paragraph mode' whereby each read will terminate when two (or more) consecutive newlines are encountered. That allows you to read each multiline record in your output in two chunks. The header line and then the rest:

#! perl -slw use strict; $/ = ''; ## Paragraph mode while( <DATA> ) { m[^(\S+)] or die "Bad input format"; my $volName = $1; $_ = <DATA>; m[Serial\sNumber\.+([^\n]+)] or die "Bad input format"; printf "%8s %s\n", $volName, $1; } __DATA__ ...

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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://752907]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-25 12:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found