Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: hashing out lines from mailq...

by GrandFather (Saint)
on May 23, 2006 at 20:25 UTC ( [id://551233]=note: print w/replies, xml ) Need Help??


in reply to hashing out lines from mailq...

Using a regex probably does it for you. Matching the parenthasised stuff ("(Deferred: ...)") may be problematic if nested parenthesis are allowed. That aside, the following should get you started:

use warnings; use strict; my $str = 'k4J37P420342 3256 10021545 May 18 23:07 MAILER-DAEMON + (Deferred: Connection reset by somdomain.com.) <someone@somedomain.c +om>'; my ($code, $addr) = $str =~ /(\S+)(?:[^)]*)\)\s*<([^>]+)/; print "$code $addr\n" if defined $addr;

Prints:

k4J37P420342 someone@somedomain.com

DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: hashing out lines from mailq...
by perlknight (Pilgrim) on May 24, 2006 at 15:04 UTC
    here's the the code, the regex for Deferred is working now, but still I am running out of idea how store multiple recipients associating with the qid, any idea?
    #!/usr/bin/perl use Data::Dumper; open (Q,"-|" , "cat mailqout" ); my $ref_tomailq= []; my $coutner = 0; my $temp_qid; while(<Q>) { # Ignore the banners and totals next if m{ Q-ID }ix ; # Ignore any completed jobs #next if m{ ^ .{10,20} \s \(job \s completed\) }x; if( m{ ^\w+ }ix ) { my @ar_line = split(/\s+/,$_); my $num_char = length($ar_line[0]); if ( $num_char > "0") { #print "$ar_line[$counter] $ar_line[-1]"; $ref_tomailq->[$counter]->{$ar_line[0]}->{"fro +m"} = $ar_line[-1]; $temp_qid = $ar_line[0]; $counter++; } } else { my @ar_line = split(/\s+/, $_); chomp(@ar_line); if ( $ar_line[1] =~ /\(Deferred:/) { $ref_tomailq->[$counter-1]->{$temp_qid}->{"sta +tus"} = "deffered"; } elsif ($ar_line[1] =~ /<{1}\w+>?/) { #print "@ar_line\n"; $ref_tomailq->[$counter-1]->{$temp_qid}->{"to" +} = $ar_line[1] } } } print Dumper($ref_tomailq);
    Thanks.

      The code I showed you does that.

      /J\

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://551233]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-20 02:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found