Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Dynamically build a table

by 2teez (Vicar)
on Mar 11, 2014 at 20:24 UTC ( [id://1077896]=note: print w/replies, xml ) Need Help??


in reply to Dynamically build a table

Hi Deep Plaid,

.. I know a hash won't work because I will have rows of data with "keys" that are duplicated, and that have multiple values..
Really? Except I don't understand what you wanted. Am sure, hash would work perfectly, using the dataset you presented like so:

use warnings; use strict; use Data::Dumper; my $file = "1.00 InDev 01-Jun-2013 1.00 InTest 15-Jul-2013 1.00 InUAT 31-Jul-2013 1.00 InProd 15-Sep-2013 1.01 InDev 01-Jul-2013 2.00 InDev 01-Aug-2013 3.00 InDev 01-Sep-2013"; my %line; for ( split /\n/, $file ) { my @datas = split; push @{ $line{ $datas[0] }{ $datas[1] } }, $datas[2]; } { $Data::Dumper::Sortkeys = 1; $Data::Dumper::Indent = 3; print Dumper \%line; }
Which gives the following output:
$VAR1 = { '1.00' => { 'InDev' => [ #0 '01-Jun-2013' ], 'InProd' => [ #0 '15-Sep-2013' ], 'InTest' => [ #0 '15-Jul-2013' ], 'InUAT' => [ #0 '31-Jul-2013' ] }, '1.01' => { 'InDev' => [ #0 '01-Jul-2013' ] }, '2.00' => { 'InDev' => [ #0 '01-Aug-2013' ] }, '3.00' => { 'InDev' => [ #0 '01-Sep-2013' ] } };
So, one out of your questions, is actually done for you, the second one you can easily do. :)!
*I hope the above helps. You can also take a look at perldsc

* Update

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me

Replies are listed 'Best First'.
Re^2: Dynamically build a table
by Deep_Plaid (Acolyte) on Mar 14, 2014 at 14:46 UTC

    Hi - sorry for not getting back to you sooner. I got caught up in corporate manure. Thanks for taking a look at this and for your advice. Another user added to what you wrote and I will try that out. Thanks again!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1077896]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-20 08:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found