John W. Krahn wrote:
> Ed wrote:
>>How would I get the various elements out of a string of known format.
>>A previous post about a similar topic approaches a solution but I need
>>help with the regular expression to pass to the m function.
>>
>>Here's an example of a string:
>>net user cknotts somepassword /add /active:yes /expires:never
>>/comment:"Some Comment" /fullname:"Cindy Knottsagain"
>>
>>The code would look something like this, except the regex in the m{}
>>function needs work:
>>
>>while (my $line = <F>)
>>{
>>     if( my( $UserName, $passwd, $Comment, $FullName ) = ( $line =~
>>m{^\s*net\+user\s+(\S+)\s+(\S+)\s*} ) )
>>     {
>>          print $UserName, $passwd, $Comment, $FullName;
>>     }
>>
>>}
> 
> Something like this (UNTESTED):
> 
> while ( my $line = <F> ) {
> 
>     if ( $line =~ /^\s*net\s+user\s+(\S+)\s+(\S+)/ ) {
>         my ( $UserName, $passwd ) = ( $1, $2 );
>         my $Comment  = $line =~ m!/comment:"([^"]+)!;
>         my $FullName = $line =~ m!/fullname:"([^"]+)!;

Sorry, I forgot to use list context.

         my ( $Comment )  = $line =~ m!/comment:"([^"]+)!;
         my ( $FullName ) = $line =~ m!/fullname:"([^"]+)!;

>         print $UserName, $passwd, $Comment, $FullName;
>         }
>     }


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to