On May 11, 8:38 am, speedj...@googlemail.com (jet speed) wrote: > Hi All, > > 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. > > FILE > ----------------------------------------------- > > 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 > > ----------------------------------------------------------- > > #!/usr/bin/perl > open(FILE, "clrlist") || die "Can't open clrlist : $!\n"; > > while (<FILE>) { > #if ($_=~ /\w{7}\s\w{4}\s\w{6}\s(\d{1,4})/i) { #workts for 1st line > ...
Also, you may want to consider the /x modifier to avoid "regex blindness", [a visual Bermuda Triangle that will cause anyone viewing it to avert their eyes and quickly paddle the other way]. Even with an easy regex, the view improves considerably with /x : if ( / \w{7} \s \w{4} \s # insert comment here... \d{1,4} # more comments... .... /ix ) Or just: / \w{7} \s \w{4} \s .... /ix; # whitespace enhanced -- Charles DeRykus -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/