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

Re: Matching text

Thread Previous | Thread Next
From:
Jon Molin
Date:
February 1, 2002 00:45
Subject:
Re: Matching text
Message ID:
3C5A54E8.CB3D6ABD@resfeber.se
Kevin wrote:
> 
> Hi
> 
> I have a really simple problem that I could solve easily with a strstr() call
> in c but cannot get my head around in perl.
> 
> 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"

something like
if ($data =~ /User ([^ ]*)/)
{
  $username = $1;
}

what happends there is that it checks for the occurance of User then a
space followed by 0-* nonspace chars. it puts the nonspace cars, ie the
username in $1 since we hve the () around that part.

you should read the documentation at 'perldoc perlre' and/or read books
about perl. My guess is that it'd take you 5 mins of reading in learning
perl to solve this problem.

/Jon


>                 $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.
> 
> Thanks
> 
> Kevin
> 
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org

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