It's a bit hard to understand your real question. But here's
a go at it anyway.
If you want to grab the whole lines that have "Name:" in it:
# Note the use of an array here.
@out = `c:/tmp/test.cmd /i $c`;
@names = grep( /Name:/, @out );
print for @names;
If you want to get the names and values into a hash:
# Note the use of an array here.
@out = `c:/tmp/test.cmd /i $c`;
for ( @out ) {
$names{$1} = $2 if /(.*)\s+Name:\s*(.*)\s*/;
}
print "$_ => $names{$_}\n" for keys %names;
Or you could do something with each line that had "Name:" in it:
# Note the use of an array here.
@out = `c:/tmp/test.cmd /i $c`;
for ( @out ) {
if ( ($key, $name) = /(.*)\s+Name:\s*(.*)\s*/ ) {
print "$key : $name\n";
}
}
--
Mike Arms
> -----Original Message-----
> From: Sabherwal, Balvinder (MBS)
> [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, January 29, 2003 9:22 AM
> To: [EMAIL PROTECTED]
> Subject: Regex question
>
>
> List,
>
> I need your help with the regex in my script.
>
> $out = `c:/tmp/test.cmd /i $c`;
>
> The above line gets the result in the variable and I'm trying
> to match a
> pattern as below and I want to store the lines in another
> variable if the
> matching pattern is found.
>
> ($name) = $out =~ m/Name\:/xo ;
>
>
> The value I get in $name is 1. Question is how do I get the
> lines from the
> $out into $name?? $out is a multiline output. The sample out
> put is as below
>
> Successful purge and preload of the NBT Remote Cache Name Table.
>
> User Information:
> ---------------------
> User Name: PINTOA
>
> Computer Information:
> ---------------------
> Computer Name: W-DEV-2103C
> IP Address: 10.90.78.7
> MAC Address: 00-C0-4F-47-64-85
>
>
> From the above output I need to strip out the below lines
> into the $name.
>
> User Name: PINTOA
> Computer Name: W-DEV-2103C
>
> Thanks for your help in advance.
> _______________________________________________
> ActivePerl mailing list
> [EMAIL PROTECTED]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs