Skip to content

Instantly share code, notes, and snippets.

@jyotty
Created April 6, 2010 04:39
Show Gist options
  • Select an option

  • Save jyotty/357226 to your computer and use it in GitHub Desktop.

Select an option

Save jyotty/357226 to your computer and use it in GitHub Desktop.
use IO::Pipeline;
use Data::Dump qw(dump);
sub ptap (;&) { my $tap = shift || sub { print }; return pgrep { $tap->(); 1 } }
my $source = <<'END';
2010-03-21 16:15:30 1NtNoI-000658-6V Completed
2010-03-21 16:17:29 1NtNlx-00062B-0R Completed
2010-03-21 16:20:37 1NtNtF-0006AE-G6 Completed
2010-03-21 16:28:37 no host name found for IP address 218.108.42.254
2010-03-21 16:28:51 H=(ZTZUWWCRQY) [218.108.42.254] F=<pansiesyd75@setupper.com> rejected RCPT <inline@trout.me.uk>: rejected because 218.108.42.254 is in a black list at zen.spamhaus.org
2010-03-21 16:28:51 unexpected disconnection while reading SMTP command from (ZTZUWWCRQY) [218.108.42.254] (error: Connection reset by peer)
2010-03-21 16:35:57 no host name found for IP address 123.122.231.66
2010-03-21 16:35:59 H=(LFMTSDM) [123.122.231.66] F=<belladonnai6@buybuildanichestore.com> rejected RCPT <tal@fyrestorm.co.uk>: rejected because 123.122.231.66 is in a black list at zen.spamhaus.org
END
open my $in, '<', \$source
or die "Failed to create filehandle from scalar: $!";
my $out;
$in
| pmap { [ /^(\S+) (\S+) (.*)$/ ] }
| ptap { dump $_ }
| pgrep { $_->[2] =~ /rejected|Completed/ }
| pmap { [ @{$_}[0, 1], $_->[2] =~ /rejected/ ? 'Rejected' : 'Completed' ] }
| pmap { join(' ', @$_)."\n" }
| ptap
| psink { $out .= $_ };
#print $out;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment