I like the following way:
use strict; use warnings; use Data::Dumper; my @data; while( <DATA> ) { chop; if ( /^(array.*|unassigned)$/ ) { push @data, $1; } else { $data[-1] .= " $_"; } } print Dumper \@data; __DATA__ array A physicaldrive 2C:1:1 port 2C:box 1:bay 1 SAS 1 TB OK physicaldrive 2C:1:2 port 2C:box 1:bay 2 SAS 1 TB OK array B physicaldrive 2C:1:3 port 2C:box 1:bay 3 SAS 1 TB OK physicaldrive 2C:1:4 port 2C:box 1:bay 4 SAS 1 TB OK unassigned physicaldrive 7C:3:7 port 7C:box 3:bay 7 SAS 1 TB OK physicaldrive 7C:3:8 port 7C:box 3:bay 8 SAS 1 TB OK
In reply to Re: Join multiple lines in a string based on regex.
by hdb
in thread Join multiple lines in a string based on regex.
by pr33
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |