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

In reply to Re^3: Message regex by ikegami
in thread Message regex by minixman

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.