Skip to content

Instantly share code, notes, and snippets.

@dkolb

dkolb/MapAbuse.pl

Created Sep 14, 2013
Embed
What would you like to do?
A blatant abuse of map and Perl Hash/Array quirks to parse some output.
#!/usr/bin/perl
use Data::Dumper;
$reports = [
'16:02:10,663 INFO [log] STNDRDTESTRESULT operation=getEntityA,endpoint=http://server01.example.com/SomeService,status=VALID',
'16:02:18,485 INFO [log] STNDRDTESTRESULT operation=getEntityB,endpoint=http://server01.example.com/SomeOtherService,status=VALID',
'16:02:18,490 INFO [log] STNDRDTESTRESULT operation=getEntityB,endpoint=http://server02.example.com/SomeOtherService,status=VALID',
'16:02:20,657 INFO [log] STNDRDTESTRESULT operation=getEntityB,endpoint=http://server03.example.com/SomeOtherService,status=VALID',
'16:02:20,657 INFO [log] STNDRDTESTRESULT operation=getEntityB,endpoint=http://server04.example.com/SomeOtherService,status=VALID',
'16:02:22,276 INFO [log] STNDRDTESTRESULT operation=getEntityB,endpoint=http://server05.example.com/SomeOtherService,status=VALID',
'16:02:22,277 INFO [log] STNDRDTESTRESULT operation=getEntityB,endpoint=http://webservices.example.com/SomeOtherService,status=VALID'
];
@processed = map {
s/^.* STNDRDTESTRESULT (.*)$/\1/;
my @kv = split ',';
my %m = map { split "=" } @kv;
\%m;
} @$reports;
print Dumper(\@processed);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.