On 4/27/11 Wed Apr 27, 2011 8:32 AM, "jet speed" <speedj...@googlemail.com> scribbled:
> Hi all, > > Thanks for all our inputs, > > The regular expression below works fine if do it for single line, i am > trying to caputre the match $1, and $2 into array. only the first line > is pushed to the array. what am i doing wrong ? > how to get all the $1 and $2 match values for each line into arrary ? > Kindly advice. > > > # more wwnlist > 0079 Not Visible 6000097000029260057253303030373 > 007A Not Visible 6000097000029260057253303030374 > 007B Not Visible 6000097000029260057253303030374 > 007C Not Visible 6000097000029260057253303030374 > 007D Not Visible 6000097000029260057253303030374 > 007E Not Visible 6000097000029260057253303030374 > more wwnmod.pl > #!/usr/bin/perl > > #0079 Not Visible 6000097000029260057253303030373 > > > open(FILE, "wwnlist") || die "Can't open wwnlist : $!\n"; > while (<FILE>) { > if ($_=~/\b(\d{4})\s[a-z]{1,3}\s[a-z]{1,7}\s*(\d{1,32})\b/i) { > push (@dev, $1); > push (@wwn, $2); > } > } > > print "@dev \n"; > print "@wwn \n"; > > ./wwnmod.pl > 0079 > 6000097000029260057253303030373 [ The metasymbol \d matches the characters [0-9], not the extended hexadecimal set that includes A-Z. To match those, construct your own character class: [0-9A-Z] So your regular expression test will become: if ($_=~/\b([0-9A-Z]{4})\s[a-z]{1,3}\s[a-z]{1,7}\s*(\d{1,32})\b/i) { -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/