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

Re: Variables as a variable name... (I know you shouldn't but...)

by broomduster (Priest)
on Aug 14, 2008 at 10:05 UTC ( [id://704316]=note: print w/replies, xml ) Need Help??


in reply to Variables as a variable name... (I know you shouldn't but...)

Hashes are a good way to have what you want. The data you show can be easily collected into a multi-layer hash, with ProductionLine as the top-level key, DayOfWeek as the second-level key, and Output as the value. (You can flip the top- and second-layer keys if it is more convenient to think of the data that way; I like the ProductionLine at the top, especially if you are going to end up plotting based on Line).

The code snippet below should get you started.

You should also have a look at perldsc and perlreftut for some basic training in complex data structures in Perl.

use strict; use warnings; use Data::Dumper; my %outputs; while ( <DATA> ) { my($day, $line, $output) = (split); $outputs{$line}{$day} = $output; } print Dumper(\%outputs); __END__ 2 CANNING 18353 2 MULTIPACK 14878 2 QUEST 911 3 CANNING 46775 3 MULTIPACK 42601 3 QUEST 1564 4 CANNING 81302 4 MULTIPACK 67542 4 QUEST 1879

Output:
$VAR1 = { 'CANNING' => { '4' => '81302', '3' => '46775', '2' => '18353' }, 'QUEST' => { '4' => '1879', '3' => '1564', '2' => '911' }, 'MULTIPACK' => { '4' => '67542', '3' => '42601', '2' => '14878' } };

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (7)
As of 2024-04-25 15:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found