On Tue, Sep 04, 2001 at 10:10:39AM -0700, [EMAIL PROTECTED] wrote:
>  root    Wed Aug 22 04:44:59 2001     DLs
[snip]

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

Yes.  Don't you?  I do.  I think the problem might lie in the difference
between what you say you want, what you expect, and what you get.  You say
you want $1 eq 'root' from "root    Wed Aug 22 04:44:59 2001     DLs", but
$1 eq 'root   '.  This is correct with what you expect, because you expect
the first seven characters.  Space is a character.

To correct this you'll have to change your current regex from:

    ^(.{7})\s+?(.{24})\s+?(\S+?)$

to something like

    ^(\S+)\s+(\S.*\S)\s+(\S+)$

This matches on whitespace boundaries, rather than column widths.  You'll
notice I removed your non-greedy specifiers (\s+?, \S+?).  They aren't doing
any good; quite the opposite, they're slowing your pattern match down for no
reason.

Given that this is columnar data, a better solution may be to use unpack:

    for (@procs) {
        my($user, $date, $state) = unpack("A8 A29 A*", $_);
        ...
    }


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--
 

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

Reply via email to