[EMAIL PROTECTED] wrote:
> 
> I posted a similar question last week; this is a rephrasing.
> 
> I have the following strings:
> 
> [snip data]
> 
> I want three things:
> 
> user, the entire date, the state.
> 
> I'm currently trying to get this with:
> 
> for(@procs){
>  /^(.{7})\s+?(.{24})\s+?(\S+?)$/;
> 
> I want $1 to be the user (e.g. 'root' 'postfix').
> I want $2 to be something like 'Wed Aug 23 05:30:01 2001'.
> I want $3 to be the state, which was a lot of forms, but which is, for
> example 'DLs' above.
> 
> Shouldn't this get the first 7, then 24 characters, then the glop that's
> left over?

Here is one way to do it:


#!/usr/bin/perl -w
use strict;

while ( <DATA> ) {
    my @data = split;
    my $user = shift @data;
    my $state = pop @data;
    my $date = "@data";

    print "User: $user\nDate: $date\nState: $state\n";
    }

__DATA__
 root    Wed Aug 22 04:44:59 2001     DLs
 root    Wed Aug 22 04:44:59 2001     ILs
 root    Wed Aug 22 04:44:59 2001     DL
 root    Wed Aug 22 04:44:59 2001     DL
 root    Wed Aug 22 04:44:59 2001     DL
 root    Wed Aug 22 04:44:59 2001     DL
 root    Wed Aug 22 04:46:37 2001     Is
 root    Wed Aug 22 11:46:38 2001     Ss
 root    Wed Aug 22 11:46:39 2001     Ss
 daemon  Wed Aug 22 11:46:40 2001     Is
 root    Wed Aug 22 11:46:41 2001     Is
 root    Wed Aug 22 11:46:41 2001     Ss
 root    Wed Aug 22 11:46:41 2001     Is
 root    Wed Aug 22 12:31:21 2001     Is
 postfix Wed Aug 22 12:31:21 2001     I
 root    Wed Aug 22 12:32:21 2001     Ss
 nobody  Wed Aug 22 12:32:21 2001     I
 nobody  Wed Aug 22 12:32:22 2001     I
 nobody  Wed Aug 22 12:32:22 2001     I
 nobody  Wed Aug 22 12:32:22 2001     I




John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to