Now I'm confused, I thought a substr would be faster than a regex in this
case as the data is formatted.
Would it?
-
#!/usr/bin/perl -w
use strict;
while ( ) {
my $user = substr($_, 0,8);
my $date = substr($_, 9,32);
my $state = subst
[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+?(\
On Tue, Sep 04, 2001 at 10:10:39AM -0700, [EMAIL PROTECTED] wrote:
> rootWed 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
John
What you're doing looks OK, but it's my guess that either the user name doesn't
start at the beginning of the line or the state doesn't finish at the end, i.e.
you have leading or trailing spaces but have anchored your pattern to the ends
of the string.
Try
foreach (
" ro
Good day;
I have the following strings:
> rootWed Aug 22 04:44:59 2001 DLs
>I want three things:
>
>user, the entire date, the state.
What is separating these attributes? A constant number of spaces, or a tab?
If so, it might be easier to use the "split" function.
($user, $date, $
This worked fine for me!
$_ = "nobody Wed Aug 22 12:32:22 2001 I";
print "$_\n";
$_ =~ s/^(.{7})\s+?(.{24})\s+?(\S+)$/$1,$2,$3/;
print "User = $1\n";
print "Date = $2\n";
print "State = $3\n";
John Way