I have bunch of text and I am trying to match a group of pattern, the regex which I am using is able to match the pattern but the problem is that it matches only the second group not the first group.
open(FILE, "match.txt") || die("Could not open file ");
my $text = do { local $/; <FILE> };
while( $text =~ m/FibreChannel SCSI Interface.*World Wide Port Number\.*(.*?)\n.*Driver\.+(.*?)\n.*Vendor Name\.+(.*?)\n/sgmp )
{
print "$1\n$2\n$3\n";
}
Prints
0x1b201
lpfc_740
Test Corporation
The above code works but it displays only the text from the second group not the first group. What am I missing here? Is there a better way to do this?
I thought it would print
0x1a101
lpfc_740
Test Corporation
0x1b201
lpfc_740
Test Corporation
------------------------ match.txt contains
\==+FibreChannel SCSI Interface :
|----Link State.........................................Down
|----World Wide Port Number.............................0x1a101
\==+SCSI Interface :
|----Driver..........................................lpfc_740
|----Queue Depth.....................................2038
\==+PCI Device :
|----Bus..........................................0x06
|----Vendor Name..................................Test Corporation
|----Slot Description.............................
\==+FibreChannel SCSI Interface :
|----Link State.........................................Down
|----World Wide Port Number.............................0x1b201
\==+SCSI Interface :
|----Driver..........................................lpfc_740
|----Queue Depth.....................................2038
\==+PCI Device :
|----Bus..........................................0x0a
|----Vendor Name..................................Test Corporation
|----Slot Description.............................