Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Help creating HASH for file comparison

by toolic (Bishop)
on Mar 27, 2013 at 17:29 UTC ( #1025764=note: print w/replies, xml ) Need Help??

in reply to Help creating HASH for file comparison

You could use a hash-of-hashes data structure (perldsc)
use warnings; use strict; my %data; while (<DATA>) { chomp; my @tokens = split /,/; my %hash; $hash{symbol } = $tokens[0]; $hash{timeStamp } = $tokens[2]; $hash{status } = $tokens[3]; $hash{bid } = $tokens[4]; $hash{bidVol } = $tokens[5]; $hash{ask } = $tokens[6]; $hash{askVol } = $tokens[7]; $data{$tokens[1]} = \%hash; } use Data::Dumper; $Data::Dumper::Sortkeys=1; print Dumper(\%data); # FILE1: __DATA__ ESM3,2285319,Q,13:58:50.744000,Q,WIDE,1549.250000,656,1549.500000,522, +0.000000,0.000000,0.000000,105,67,N,CME,CME ESM3,2285247,T,13:58:49.986000,SELL,1549.250000,2,0,1738560,,U ESM3,2285320,Q,13:58:50.749000,Q,WIDE,1549.250000,656,1549.500000,524, +0.000000,0.000000,0.000000,105,68,N,CME,CME ESM3,2285321,Q,13:58:50.750000,Q,WIDE,1549.250000,655,1549.500000,524, +0.000000,0.000000,0.000000,104,68,N,CME,CME ESM3,2285325,Q,13:58:50.801000,Q,WIDE,1549.250000,655,1549.500000,522, +0.000000,0.000000,0.000000,104,67,N,CME,CME ESM3,2285326,Q,13:58:50.802000,Q,WIDE,1549.250000,656,1549.500000,522, +0.000000,0.000000,0.000000,105,67,N,CME,CME ESM3,2285328,Q,13:58:50.831000,Q,WIDE,1549.250000,667,1549.500000,522, +0.000000,0.000000,0.000000,106,67,N,CME,CME ESM3,2285329,Q,13:58:50.832000,Q,WIDE,1549.250000,1504,1549.500000,522 +,0.000000,0.000000,0.000000,107,67,N,CME,CME ESM3,2285330,Q,13:58:50.833000,Q,WIDE,1549.250000,1505,1549.500000,522 +,0.000000,0.000000,0.000000,108,67,N,CME,CME ESM3,2285331,Q,13:58:50.833000,Q,WIDE,1549.250000,1506,1549.500000,522 +,0.000000,0.000000,0.000000,109,67,N,CME,CME ESM3,2285332,Q,13:58:50.833000,Q,WIDE,1549.250000,1506,1549.500000,520 +,0.000000,0.000000,0.000000,109,66,N,CME,CME ESM3,2285333,Q,13:58:50.833000,Q,WIDE,1549.250000,1506,1549.500000,519 +,0.000000,0.000000,0.000000,109,65,N,CME,CME ESM3,2285334,Q,13:58:50.833000,Q,WIDE,1549.250000,1507,1549.500000,519 +,0.000000,0.000000,0.000000,110,65,N,CME,CME

Here's a snippet of the output:

$VAR1 = { '2285247' => { 'ask' => '2', 'askVol' => '0', 'bid' => 'SELL', 'bidVol' => '1549.250000', 'status' => '13:58:49.986000', 'symbol' => 'ESM3', 'timeStamp' => 'T' }, '2285319' => { 'ask' => '1549.250000', 'askVol' => '656', 'bid' => 'Q', 'bidVol' => 'WIDE', 'status' => '13:58:50.744000', 'symbol' => 'ESM3', 'timeStamp' => 'Q' },

Replies are listed 'Best First'.
Re^2: Help creating HASH for file comparison
by jb60606 (Acolyte) on Mar 28, 2013 at 00:04 UTC
    I think that this brings me very close to my target. However, when I add the second file (to compare the first against), how do I compare the keys and elements of the two different hashes? Also, do I have any options in terms of how the output is formatted?
        sorry, was the first link a typo? It links back to one of my replied "Re: Help creating HASH for file comparison". thanks

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1025764]
[stevieb]: in a C++ header file, if a function declaration is listed twice with each listing containing different params, that's just essentially allowing one function accept two different arg lists, yes?
[stevieb]: int func(int x, int y);
[stevieb]: int func(int x);
[stevieb]: For example

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2017-06-28 23:56 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (653 votes). Check out past polls.