----- Original Message ----- From: "Kevin" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> 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 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]