develooper Front page | perl.beginners | Postings from February 2002

Re: Matching text

Thread Previous | Thread Next
From:
Leon
Date:
February 1, 2002 01:02
Subject:
Re: Matching text
Message ID:
001501c1ab85$658687c0$b450a9cb@S7575530
----- Original Message -----
From: "Kevin" <khanperl@arcom.com.au>
To: <beginners@perl.org>
Sent: Thursday, January 31, 2002 10:15 PM
Subject: Matching text

> I have have the following input.
>
> Active Accounted actions on tty57, User fred Priv 1
>  Task ID 35176, Network Accounting record, 02:04:00 Elapsed
>
> what I want to do is
>
>    for $data (@raw_data){
> if $data contains "User"
> $username = [the word after User];
>    }
>
> The length of this string can vary so I cannot rely on "User" being at n
> charcters from beginning or end of string.
>
> I am sure it is a RegEx problem but any help/pointers appreciated.

How about this :-

foreach $data (@raw_data){
              if ($data =~/User (\b\w+\b)/){
                 $username = $1;
              };
};

a shortcut would be 
foreach (@raw_data){
              if (/User (\b\w+\b)/){
                 $username = $1;
              };
};

or 
do {$username = $1 if (/User (\b\w+\b)/)} foreach (@raw_data); 


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About