Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Thanks for your reply. I am reading a CSV file(below) and creating a temporary complex hash structure as described to perform some operations. As you can see my $key is the time which should be only one per second and plug the data as hash/array.
NAME,06/01/2011,09:30:00,16.76,756,Q,00 NAME,06/01/2011,09:30:00,16.76,300,Q,00 NAME,06/01/2011,09:30:00,16.76,100,Q,00 NAME,06/01/2011,09:30:01,16.76,100,Q,00 NAME,06/01/2011,09:30:01,16.76,200,Z,00 NAME,06/01/2011,09:30:02,16.77,200,X,00 NAME,06/01/2011,09:30:02,16.77,200,X,00

Open 100k line CSV file and read using Text_CSV. I have to undef the hashes before jumping to next second.
my $csv = Text::CSV_XS->new(); open (FILE, "<", "$tickdir/$file") or die "Can't open CSV File:$! +\n"; while (<FILE>) { $csv->parse($_); my @columns = $csv->fields(); my $key = str2time($columns[1].' '.$columns[2]); my (@prices, @volumes) = (); my %HOH = (); $HOH{$key}{"name"} = $columns[0]; push(@{$HOH{$key}{"price"}}, $columns[3]); push(@{$HOH{$key}{"volumes"}}, $columns[4]); print Dumper(\%HOH); } close FILE;
OUTPUT: As you can see the key values are same.
$VAR1 = { '1306935005' => { 'volumes' => [ '200' ], 'name' => 'NAME', 'price' => [ '16.76' ] } }; $VAR1 = { '1306935005' => { 'volumes' => [ '400' ], 'name' => 'NAME', 'price' => [ '16.76' ] } };

In reply to Re^2: Hashes of Hashes of Arrays? Is it possible? by capriguy84
in thread Hashes of Hashes of Arrays? Is it possible? by capriguy84

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (1)
As of 2022-01-28 23:37 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (74 votes). Check out past polls.