Preceptor has asked for the wisdom of the Perl Monks concerning the following question:
This pattern is repeated a lot of times, once for each volume in my storage array.Symmetrix ID: Device Physical Name : \\.\PHYSICALDRIVE1 Device Symmetrix Name : 0062 (VCM) Device Serial ID : 6000062081 Symmetrix ID : 002020202220 Attached BCV Device : N/A Attached VDEV TGT Device : N/A Vendor ID : EMC Product ID : SYMMETRIX Product Revision : 5772 Device WWN : 222222222222222222 Device Emulation Type : FBA Device Defined Label Type: N/A Device Defined Label : N/A Device Sub System Id : 0x0001 Cache Partition Name : DEFAULT_PARTITION Device Block Size : 512 Device Capacity { Cylinders : 6 Tracks : 90 512-byte Blocks : 11520 MegaBytes : 6 KiloBytes : 5760 } Device Configuration : 2-Way Mir (Non-Exclusive Access) Device is WORM Enabled : No Device is WORM Protected : No SCSI-3 Persistent Reserve: Disabled Dynamic Spare Invoked : No Dynamic RDF Capability : None STAR Mode : No STAR Recovery Capability : None STAR Recovery State : NA Device Service State : Normal
That sort of thing. But that seems ... well, just rather inelegant really, when I'm pretty sure I can do multi-line regexps. I just can't quite get my head around how to turn at multi-line RE into 'something useful' for a 'foreach' loop, with multiple values.my $symm_id; foreach ( `symdev list -v` ) { if ( m/Symmetrix ID/ ) { $symm_id = ( m/Symmetrix ID\s+:\s+(\d+)/ ); } }
Well, approximately - that's not quite what I want to do, as the greedy matches will eat the intervening chunks of the command output. But essentially, I want to do that 'per record'. Given the output of this particular command generates around 400Mb, I may end up dumping it to a file first.my $text_to_parse = `symdev list -v`; my ( $dev, $sym, $config, $SCSI3 ) = ( $text_to_parse =~ m/Device Symmetrix Name\s+\:\s+([A-F0-9]+).*S +ymmetrix ID\s+\:\s+(\d+).*Device Capacity.*Cylinders\s+\:\s+(\d+).*SC +SI-3 Persistent Reserve\s+\:\s+(\w+)/m ); print "$dev, $sym, $config, $SCSI3\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Multiple line records from a command string
by BrowserUk (Patriarch) on Feb 23, 2010 at 15:18 UTC | |
by molecules (Monk) on Feb 23, 2010 at 17:33 UTC | |
by shmem (Chancellor) on Feb 23, 2010 at 18:18 UTC | |
by Anonymous Monk on Feb 23, 2010 at 20:10 UTC | |
by spq (Friar) on Feb 23, 2010 at 15:40 UTC | |
by BrowserUk (Patriarch) on Feb 23, 2010 at 16:02 UTC | |
by Preceptor (Deacon) on Feb 24, 2010 at 08:39 UTC | |
|
Re: Multiple line records from a command string
by toolic (Bishop) on Feb 23, 2010 at 15:51 UTC | |
|
Re: Multiple line records from a command string
by zwon (Abbot) on Feb 23, 2010 at 15:10 UTC |