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__ ...
|
|---|