in reply to Re^2: Message regex
in thread Message regex
Should
31=aaaaaa38=bbbbbbb
return
31 => 'aaaaaa', 38 => 'bbbbbbb'
or
31 => 'aaaaaa3', 8 => 'bbbbbbb'
That's why @tags must be populated in advance and must be in order
use strict; use warnings; my @tags = qw( 8 9 35 49 56 50 57 34 52 81 11 14 17 20 31 32 37 38 39 54 55 60 50 51 98 109 163 167 200 207 40 44 113 56 10 ); my $re = '\\[' . join('', map { "($_)=(.*?)" } @tags) . '\\]'; while (<DATA>) { chomp; my %hash = /$re/; if (not %hash) { warn("Line $. did not match\n"); next; } foreach my $tag (@tags) { printf("%-3s => %s\n", $tag, $hash{$tag}); } print("\n"); } __DATA__ 2005/11/18 00:07:18:328: FIXPump: Received data on connection {OBMSCNX +} [8=FIX.4.29=040535=849=EXLINK256=DB_ORDER50=DESRISKGATEWAY57=DCN323 +0134=4045652=20051118-05:07:181=ATOP116=0.0000000011=DES:fud632_20051 +11814=15.000017=0131730438520=031=1531.0000000032=1.000037=1317260632 +38=15.000039=254=255=NamerOfContr60=20051118-05:07:18150=2151=0.00001 +98=13173047161317260632109=DCN3230163=0167=FUT200=200512207=TSE40=244 +=1531.000000005113=06556=20051117-23:06:4910=021]
or with sorted output:
use strict; use warnings; my @tags = qw( 8 9 35 49 56 50 57 34 52 81 11 14 17 20 31 32 37 38 39 54 55 60 50 51 98 109 163 167 200 207 40 44 113 56 10 ); my @sorted_tag = sort { $a <=> $b } @tags; my $re = '\\[' . join('', map { "($_)=(.*?)" } @tags) . '\\]'; while (<DATA>) { chomp; my %hash = /$re/; if (not %hash) { warn("Line $. did not match\n"); next; } foreach my $tag (@sorted_tags) { printf("%-3s => %s\n", $tag, $hash{$tag}); } print("\n"); } __DATA__ 2005/11/18 00:07:18:328: FIXPump: Received data on connection {OBMSCNX +} [8=FIX.4.29=040535=849=EXLINK256=DB_ORDER50=DESRISKGATEWAY57=DCN323 +0134=4045652=20051118-05:07:181=ATOP116=0.0000000011=DES:fud632_20051 +11814=15.000017=0131730438520=031=1531.0000000032=1.000037=1317260632 +38=15.000039=254=255=NamerOfContr60=20051118-05:07:18150=2151=0.00001 +98=13173047161317260632109=DCN3230163=0167=FUT200=200512207=TSE40=244 +=1531.000000005113=06556=20051117-23:06:4910=021]
Output
8 => FIX.4.2 9 => 0405 10 => 021 11 => DES:fud632_20051118 14 => 15.0000 17 => 01317304385 20 => 0 31 => 1531.00000000 32 => 1.0000 34 => 40456 35 => 8 37 => 1317260632 38 => 15.0000 39 => 2 40 => 2 44 => 1531.000000005 49 => EXLINK2 50 => 21 50 => 21 51 => 0.00001 52 => 20051118-05:07:1 54 => 2 55 => NamerOfContr 56 => 20051117-23:06:49 56 => 20051117-23:06:49 57 => DCN32301 60 => 20051118-05:07:181 81 => ATOP116=0.00000000 98 => 13173047161317260632 109 => DCN3230 113 => 065 163 => 0 167 => FUT 200 => 200512 207 => TSE
|
|---|