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

Regards

Sj


On 4/27/11, Rob Dixon <rob.di...@gmx.com> wrote:
> On 27/04/2011 11:47, jet speed wrote:
>>
>> Please could you advice, how can i write a regular expression for the
>> line below to capture 0079 and 6000097000029260057253303030373
>>
>>
>> 0079 Not Visible             6000097000029260057253303030373
>>
>> i tried this one, no luck
>>
>> /(^\d{4})\s\w+\s\w+\s+\d+/ig)
>
> It works fine! You are simply not capturing the second sequence of
> digits. This
>
> use strict;
> use warnings;
>
> for ('0079 Not Visible             6000097000029260057253303030373') {
>    print /(^\d{4})\s\w+\s\w+\s+(\d+)/ig ? "$1 $2" : 'no match';
> }
>
> prints '0079 6000097000029260057253303030373'.
>
> But, depending on your data, there may be no need to match the line so
> precisely. This does the same thing
>
> use strict;
> use warnings;
>
> for ('0079 Not Visible             6000097000029260057253303030373') {
>    my @n = (split)[0,-1];
>    print "@n";
> }
>
>
> HTH,
>
> Rob
>

-- 
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