I’m trying to grep the values starting with “1. Virtualization” to “2.Virtualization” using regular expression in perl. There are lot of data in between 1.Virutalization and 2.Virtualization in an array.
Sample of my array contents as shown below.
“1. Virtualization Capacity Management Number of incidents as a result of poor performance 0 999 10 5 4 Cost of production of Capacity Plan 10K 100K 80K 30K 10K Number of unplanned purchases of capacity 0 999 15 10 5 2.Virtualization Finance Management Number of incidents as a result of poor performance 0 999 10 5 4 Cost of production of Capacity Plan 10K 100K 80K 30K 10K”
How can I write a controlled loop which greps values between 1. and 2. In between 1 and 2 it should even grep the data “Cost of production of Capacity Plan 10K 100K 80K 30K 10K” and put in one array location.
I tried writing some piece of code was not able to understand how to write a controlled loop. Can anybody help me out with this problem.
foreach (@array) {
if ($_ =~ /\d+\.\s+Virtualization.*/) { #greps values starting in 1. Virtualizaton
push (@node_level1, "$_"); #stores in the node_level1
} elsif ($_ =~ /(\%\s+.*)/) { #greps values beginning with % Number of Nodes
# print "$_\n";
}
}
Thanks in advance.
Using a state holder: