On 11-05-11 11:38 AM, jet speed wrote:
I need help in matching the regular expression, the file is as below.

I am trying to match number followed by Number ex 587, 128 in $1 and
60:06:01:60:42:40:21:00:3A:AA:55:37:91:8A:DF:11 in $2

the $1 match works find with regulare expression  #if ($_=~
/\w{7}\s\w{4}\s\w{6}\s(\d{1,4})/i) { #workts for 1st line

However i am not sure how to get both $1 and $2 togather.

Ideally i would like to have an output printed

print "$1 wwn is $2 \n";

Any help on this would be much appreciated.

You are trying to do too much in one regular expression. Process the file one line at a time.

#!/usr/bin/env perl

use strict;
use warnings;

my $lun = 0;
while( <DATA> ){
  if( /^\s*LOGICAL\s+UNIT\s+NUMBER\s+(\d+)/ ){
    $lun = $1;
  }elsif( /^UID:\s*(\S+)/ ){
    print "$lun wwn is $1 \n";
  }
}

__DATA__


LOGICAL UNIT NUMBER 587
UID:                        60:06:01:60:42:40:21:00:3A:AA:55:37:91:8A:DF:11

LOGICAL UNIT NUMBER 128
UID:                        60:06:01:60:50:40:21:00:D0:23:D5:C2:BA:D9:DE:11

LOGICAL UNIT NUMBER 763
UID:                        60:06:01:60:50:40:21:00:25:C6:3F:A7:CA:2D:DF:11




--
Just my 0.00000002 million dollars worth,
  Shawn

Confusion is the first step of understanding.

Programming is as much about organization and communication
as it is about coding.

The secret to great software:  Fail early & often.

Eliminate software piracy:  use only FLOSS.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to