STEVEN WHALEY wrote:
> 
> The program I'm trying to write requires me to grab a specific set of
> multiline output from a command and store it in an array.  I have output
> that looks like this:
>
[lengthy data snipped]
> 
> and make each line an entry in an array.  I do not actually need the
> first two lines, but I can pop them off so grabbing them isn't a
> problem.  I can get a regex to match the "Folder Path:..." line but I'm
> not sure how to get the rest of the section, up to the next empty line,
> into an array.  

First of all, in case your data is currently in a single long string, lets say
$data, do this to it.

my @data = split /\n/, $data;     # Split into one line per array element
s/^\s+//, s/\s+$// foreach @data; # Remove leading and trailing whitespace
@data = grep /\S/, @data;         # Remove all blank lines

Now to extract part of @data into @section do this

my @section = grep(
  (/Folder Path.*ag-bartend-srv/ ... /Folder Path/) =~ /^\d+$/,
  @data,
);

which copies lines into @section starting at the first one containing 'Folder
Path' and 'ag-bartend-srv', and up but not including the next line that contains
'Folder Path'.

Then

print "$_\n" foreach @section;

to show what we've caught :)

HTH,

Rob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to