[ create a new paste ] login | about

Link: http://codepad.org/rhTLTMBR    [ raw code | output | fork ]

Perl, pasted on Jun 6:
1
2
3
4
5
6
7
8
9
10
11
use Data::Dumper;
my $re = '^' . '([^@]*)@'x4 . '(.*)@([^@]*)$';
 
for my $line (
    '2012-05-29@joedoe@example.com@AB99-5@440 4.4.1 Some error occurred@XYZ35',
    '2012-05-29@foobar@invalid.com@ZZ88-6@550 5.1.1 <foobar@invalid.com>... User Unknow@GGH93',
    '2012-05-29@barfoo@invalid.com@YY88-0@550 5.1.1 barfoo@invalid.com no such user@GGH93',
) {
    my @fields = $line =~ /$re/ or die "can't parse '$line'";
    print Data::Dumper->Dump([@fields])."\n";
}


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$VAR1 = '2012-05-29';
$VAR2 = 'joedoe';
$VAR3 = 'example.com';
$VAR4 = 'AB99-5';
$VAR5 = '440 4.4.1 Some error occurred';
$VAR6 = 'XYZ35';

$VAR1 = '2012-05-29';
$VAR2 = 'foobar';
$VAR3 = 'invalid.com';
$VAR4 = 'ZZ88-6';
$VAR5 = '550 5.1.1 <foobar@invalid.com>... User Unknow';
$VAR6 = 'GGH93';

$VAR1 = '2012-05-29';
$VAR2 = 'barfoo';
$VAR3 = 'invalid.com';
$VAR4 = 'YY88-0';
$VAR5 = '550 5.1.1 barfoo@invalid.com no such user';
$VAR6 = 'GGH93';



Create a new paste based on this one


Comments: