Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot


by SamCG (Hermit)
on Jun 06, 2005 at 17:05 UTC ( #463994=snippet: print w/replies, xml ) Need Help??
Description: OATS (Order Audit Trail System) are standardized csv files produced by the NASD for Order tracking purposes. Unfortunately, each record tends to place similar data in vastly different columns, making the file itself basically human-unreadable. The record layout is based on the code in field 2.

I wasn't entirely thrilled with the ways I was imagining to do this, so a query to the chatterbox was rewarded with several monks pointing me to RoyJohnson's piece on function dispatch tables here. I was most pleased.

Comments appreciated.

Done on a windows box, for a windows network. Sorry, I'm not infrastructure.
Oh, the email via blat was forced on me. I've always preferred Mail::Sender myself.
#! perl -w

my $blat = 'C:\blat\blat.exe ';

@recips = ('');

$date = time();
(undef, undef, undef, $day, $mon, $year) = localtime $date;
$year = $year + 1900;
$data = "OATS";
$current=$year.sprintf("%02d",$mon).sprintf("%02d", $day);

$data = $whereto.$data;
#print $data."\n";

($currentfile) = reverse glob($data."\\*.lis");

$translate = $data."\\OATS.".$current.".csv";

%disp_table = ('OE'=>\&oentry, 'NW'=>\&nwentry,
'CL'=>\&clentry, 'EX'=>\&exentry, 'OR'=>\&orentry, 'CL'=>\&clentry,
'RT'=>\&rtentry, 'CR'=>\&crentry);

open IN, "<".$currentfile;
open OUT, "+>$translate";
print OUT 'Record Type, OE Type, Receive Firm ID, Received Date, Order
+ ID, Routing Firm MP ID, Symbol, Buy/Sell, Shares/Quantity, Limit Pri
+ce, Time in Force, Account Type, Method Code, Special Handling, Branc
+h Seq #, Event Timestamp, Cancel Type, Cancel Flag, Received OE ID, O
+rder Firm, Action Code, Ex. Time, Routing Firm, Replaced Order ID, Re
+placed Order time'."\n";
while (<IN>){
    @row = split /,/;
    if ($row[0] eq '#OE#'){

close IN;
close OUT;

open TXT, ">$data\\msg.txt";
print TXT "OATS feed file report for ".$date;
close TXT;

for (@recips){
    system ($blat.$data."\\msg.txt".' -to "'.$_.'" -attach "'.$transla

sub exentry {
  ($rectype, $oetype, $recdate, $orderid, $timestamp, $branchseq, $qua
+ntity, $symbol) =
  @_[0, 1, 7, 8, 9, 10, 11, 14];


sub rtentry{
($rectype, $oetype, $action, $ROEID, $orfirm,  $recdate, $orderid) =
  @_[0, 1, 2, 3, 6, 7,8];
($rtfirm, $symbol, $xtime, $quantity, $method)=
  @_[9, 11, 12, 13, 14];

sub clentry{
($rectype, $oetype, $action, $ROEID, $orfirm,  $recdate, $orderid, $sy
+mbol, $timestamp) =
  @_[0, 1, 2, 3, 6, 7,8, 9, 10];
($ccltype, $cclflag) = @_[11, 14];

sub crentry{
($rectype, $oetype, $action, $ROEID, $orfirm,  $recdate, $orderid) =
  @_[0, 1, 2, 3, 6, 7,8];
($ordertimer, $orderidr, $orderid, $rtfirm, $xtime, $method, $symbol,
$side, $quantity, $limit, $tif, $spechand, $accttype) =
@_[7, 8, 10, 11, 13, 14, 15, 16, 17, 18, 21, 25, 33];

sub nwentry{
  ($rectype, $oetype, $recdate, $orderid, $mpid, $timestamp,
   $method, $symbol, $side, $quantity, $limit, $tif, $accttype) =
  @_[0, 1, 7, 8, 9, 10, 12, 13, 14, 15, 16, 19, 31];

sub oentry{
  ($rectype, $oetype, $action, $recdate, $orderid, $mpid, $timestamp,
   $symbol, $side, $limit, $tif, $spechand, $accttype, $branchseq, $qu
+antity) =
  @_[0, 1, 2, 7, 8, 9, 10,13, 14, 15, 18, 22, 30, 34, 35];

sub orentry{
    ($rectype, $oetype, $recdate, $orderid, $mpid, $timestamp,
   $symbol, $side, $limit, $tif, $accttype, $quantity) =
  @_[0, 1, 7, 8, 9, 10,13, 14, 15, 19, 31, 35];

sub prtout{
  $recdate = &formDate($recdate);
  $timestamp = &formDate($timestamp);
  $xtime = &formDate($xtime);
  $ordertimer = &formDate($orderTimer);
  print OUT join ', ', ($rectype, $oetype, $recid, $recdate, $orderid,
+ $mpid, $symbol,
  $side, $quantity, $limit, $tif, $accttype, $method, $spechand, $bran
+chseq, $timestamp,
  $ccltype, $cclflag, $ROEID, $orfirm, $action, $xtime, $rtfirm,
  $orderidr, $ordertimer);
  print OUT "\n";


sub initvar{
  $rectype=$oetype= $recid= $recdate= $orderid= $mpid= $symbol=
  $side= $quantity= $limit= $tif=$accttype= $method= $spechand= $times
+tamp = $branchseq=
  $action= $ROEID= $orfirm= $ccltype= $cclflag=$xtime=$rtfirm=

sub deft{
  return 1;

sub formDate{
  my $enter = shift;
  $enter =~ s!(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})!$2/$3/$1:$4:$
  return $enter;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://463994]
[LanX]: Socrates was a Troll
[Your Mother]: It's very, very dangerous... Thinking that a group is intrinsically evil... buries the fact that all humans can be so deep that it starts to become likely they will be.
[Your Mother]: LanX++
[Corion]: (also the "troll for trolls sake" could seen be much like the "punk for punks beer")
[Your Mother]: I'm completely (historically anyway) a troll in real life. It's not fun online, you can't really win. :P
Happy-the-monk orders a Punk IPA.
[Your Mother]: Also, I'm too old to start fights with strangers anymore.
[LanX]: concentrating on omestic violence?
[LanX]: d
[Your Mother]: Open air violence. Or on campus.

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (18)
As of 2018-03-19 13:49 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (240 votes). Check out past polls.