Naveen
Naveen

Reputation: 177

tokenize the message in perl

i have to tokenize a FIX ( Financial Information Exchange ) message in to tag and values using Perl, We have different type of messages like ExecutionReport, NewOrderSingle, CancelRequest.. Msg in log file looks like below

2011-02-17 12:01:46,870 INFO ExecutionReport (8=FIX.4.29=33235=849=ZZZ56=XXXX34=455452=20110217-17:01:4650=MCDV57=kgs37=86669611=2732655.1876=BBBB17=21728781020=0150=139=155=HHHHH48=44490310822=1207=US54=138=12000040=115=USD59=032=10031=26.15151=11200014=80006=26.1472560=20110217-17:01:4658=COT100 at 26.15(USD) for ORDER ID #86669664=201102235847=VVV10=221)

I want to split this message as

  1. token1 : type of msg ( ExecutionReport )
  2. token2 : actual msg ( (8=FIX4.2....10=221)

how to omit initial some characters in msg ( like date, time, INFO etc ) & split this message in to above 2 parts using perl...?

(Note : Don't get confused, actual data is delimeted by Control Character (^A).. not visible here )

Thanks

Upvotes: 0

Views: 317

Answers (2)

maerics
maerics

Reputation: 156464

It looks like you just want to split on whitespace, so try something like this:

my $logline = "2011-02-17 12:01:46,870 INFO ExecutionReport (8=FIX.4.29=3...";
my ($date, $time, $level, $type, $msg) = split(/\s+/, $logline, 5);

Now you can handle each token separately and the variables $type and $msg hold the two elements you specifically mentioned.

Upvotes: 1

DVK
DVK

Reputation: 129433

You can try to use PFIX CPAN module

Upvotes: 1

Related Questions