Michael Alipio wrote:
> Hi,

Hello,

[ snip ]

> Now, my goal is to adapt that code, particularly
> obtaining only Start, IP, User. However, those three
> targets are not anymore located at the beginning of a
> line.
> 
> "Start" is the date=.time= combination,
> "IP" is found after rem_ip=
> "User" is found after "user: "
> 
> I'm not really sure how to put my regexp inside my
> hash..
> 
> while ( <LOGFILE> ) {
>     my %extr = (
>         Start => '',
>         IP    => '',
>         User  => '',
>         /what should i put here??/mg
>         );
>     print "Start:$extr{Start} IP:$extr{IP}
> User:$extr{User}\n\n";
>     }

You don't really need a hash, you could probably do something like this:

$/ = '';
while ( <LOGFILE> ) {
    print
        'Start:', /date=([^,\s]+)/,
        ' ',      /time=([^,\s]+)/,
        ' IP:',   /rem_ip=([^,\s]+)/,
        ' User:', /user:\s*(\S+)/,
        "\n\n";
    }



John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall

-- 
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