simple hash of arrays, I cant see the trees for the forest

B

bpatton

I'm trying to get something on the order of

$VAR1 = {
'cell' => {
'1A' => {
'pass' => {
'ACTIVE' => {
[ 0 , 0 , 0 , 240 , 240 , 240 , ... ] ,
[ 1 , 2 , 3 , 4 , 5 , 6 , ... ] ,
},
},
'fail'=> {
'ACTIVE'=>{
....


This shoudl be very easy to do, but I've been working on my AC and had
a beer on an empty
stomach.
Here's some sample sode that soes not work.
#!/usr/local/bin/perl
use strict;
use warnings;

use Data::Dumper; $Data::Dumper::Indent = 1;
my $data;
my $x = 0;
my $y = 0;
my $dis = 240;
my $rule = '1A';
my $layer = 'ACTIVE';
$data->{cell}->{$rule}->{pass}->{$layer} =
( $x,$y , $x,$y+$dis , $dis,$dis , $dis,$y , $x,$y);
$x = $dis * 3;
$y = $dis * 3;
$data->{cell}->{$rule}->{pass}->{$layer} =
( $x,$y , $x,$y+$dis , $dis,$dis , $dis,$y , $x,$y);
$dis = int($dis / 2);
$data->{cell}->{$rule}->{fail}->{$layer} =
( $x,$y , $x,$y+$dis , $dis,$dis , $dis,$y , $x,$y);
$x = $dis * 3;
$y = $dis * 3;
$data->{cell}->{$rule}->{fail}->{$layer} =
( $x,$y , $x,$y+$dis , $dis,$dis , $dis,$y , $x,$y);
print Dumper($data);
 
X

Xicheng Jia

bpatton said:
I'm trying to get something on the order of

$VAR1 = {
'cell' => {
'1A' => {
'pass' => {
'ACTIVE' => {
[ 0 , 0 , 0 , 240 , 240 , 240 , ... ] ,
[ 1 , 2 , 3 , 4 , 5 , 6 , ... ] ,
},
},
'fail'=> {
'ACTIVE'=>{
...


This shoudl be very easy to do, but I've been working on my AC and had
a beer on an empty
stomach.
Here's some sample sode that soes not work.
#!/usr/local/bin/perl
use strict;
use warnings;

use Data::Dumper; $Data::Dumper::Indent = 1;
my $data;
my $x = 0;
my $y = 0;
my $dis = 240;
my $rule = '1A';
my $layer = 'ACTIVE';
$data->{cell}->{$rule}->{pass}->{$layer} =
( $x,$y , $x,$y+$dis , $dis,$dis , $dis,$y , $x,$y);
$x = $dis * 3;
$y = $dis * 3;
$data->{cell}->{$rule}->{pass}->{$layer} =
( $x,$y , $x,$y+$dis , $dis,$dis , $dis,$y , $x,$y);
$dis = int($dis / 2);
$data->{cell}->{$rule}->{fail}->{$layer} =
( $x,$y , $x,$y+$dis , $dis,$dis , $dis,$y , $x,$y);
$x = $dis * 3;
$y = $dis * 3;
$data->{cell}->{$rule}->{fail}->{$layer} =
( $x,$y , $x,$y+$dis , $dis,$dis , $dis,$y , $x,$y);
print Dumper($data);

you may want to change some braces into brackets, like:

$data->{cell}->{$rule}->{pass}->{$layer} =
[ $x,$y , $x,$y+$dis , $dis,$dis , $dis,$y , $x,$y ];

Good luck,
Xicheng
 
X

Xicheng Jia

Xicheng said:
bpatton said:
I'm trying to get something on the order of

$VAR1 = {
'cell' => {
'1A' => {
'pass' => {
'ACTIVE' => {
[ 0 , 0 , 0 , 240 , 240 , 240 , ... ] ,
[ 1 , 2 , 3 , 4 , 5 , 6 , ... ] ,
},
},
'fail'=> {
'ACTIVE'=>{
...


This shoudl be very easy to do, but I've been working on my AC and had
a beer on an empty
stomach.
Here's some sample sode that soes not work.
#!/usr/local/bin/perl
use strict;
use warnings;

use Data::Dumper; $Data::Dumper::Indent = 1;
my $data;
my $x = 0;
my $y = 0;
my $dis = 240;
my $rule = '1A';
my $layer = 'ACTIVE';
$data->{cell}->{$rule}->{pass}->{$layer} =
( $x,$y , $x,$y+$dis , $dis,$dis , $dis,$y , $x,$y);
$x = $dis * 3;
$y = $dis * 3;
$data->{cell}->{$rule}->{pass}->{$layer} =
( $x,$y , $x,$y+$dis , $dis,$dis , $dis,$y , $x,$y);
$dis = int($dis / 2);
$data->{cell}->{$rule}->{fail}->{$layer} =
( $x,$y , $x,$y+$dis , $dis,$dis , $dis,$y , $x,$y);
$x = $dis * 3;
$y = $dis * 3;
$data->{cell}->{$rule}->{fail}->{$layer} =
( $x,$y , $x,$y+$dis , $dis,$dis , $dis,$y , $x,$y);
print Dumper($data);

you may want to change some braces into brackets, like:

$data->{cell}->{$rule}->{pass}->{$layer} =
[ $x,$y , $x,$y+$dis , $dis,$dis , $dis,$y , $x,$y ];

s/braces/parentheses/;
 
B

bpatton

That did it , thanks :)

Xicheng said:
bpatton said:
I'm trying to get something on the order of

$VAR1 = {
'cell' => {
'1A' => {
'pass' => {
'ACTIVE' => {
[ 0 , 0 , 0 , 240 , 240 , 240 , ... ] ,
[ 1 , 2 , 3 , 4 , 5 , 6 , ... ] ,
},
},
'fail'=> {
'ACTIVE'=>{
...


This shoudl be very easy to do, but I've been working on my AC and had
a beer on an empty
stomach.
Here's some sample sode that soes not work.
#!/usr/local/bin/perl
use strict;
use warnings;

use Data::Dumper; $Data::Dumper::Indent = 1;
my $data;
my $x = 0;
my $y = 0;
my $dis = 240;
my $rule = '1A';
my $layer = 'ACTIVE';
$data->{cell}->{$rule}->{pass}->{$layer} =
( $x,$y , $x,$y+$dis , $dis,$dis , $dis,$y , $x,$y);
$x = $dis * 3;
$y = $dis * 3;
$data->{cell}->{$rule}->{pass}->{$layer} =
( $x,$y , $x,$y+$dis , $dis,$dis , $dis,$y , $x,$y);
$dis = int($dis / 2);
$data->{cell}->{$rule}->{fail}->{$layer} =
( $x,$y , $x,$y+$dis , $dis,$dis , $dis,$y , $x,$y);
$x = $dis * 3;
$y = $dis * 3;
$data->{cell}->{$rule}->{fail}->{$layer} =
( $x,$y , $x,$y+$dis , $dis,$dis , $dis,$y , $x,$y);
print Dumper($data);

you may want to change some braces into brackets, like:

$data->{cell}->{$rule}->{pass}->{$layer} =
[ $x,$y , $x,$y+$dis , $dis,$dis , $dis,$y , $x,$y ];

Good luck,
Xicheng
 
U

Uri Guttman

b> That did it , thanks :)

regardless of the fix, your code leave much to be desired. perhaps you
should drink a better beer on an empty stomach?

you don't need -> between sets of [] or {}.

all that redundancy is slow and very ugly. get a ref to the lowest level
that you are munging and use that:

my $rule_ref = \$data->{cell}{$rule} ;

my $coords = [$x,$y , $x,$y+$dis , $dis,$dis , $dis,$y , $x,$y] ;

$rule_ref->{pass}{$layer} = $coords ;

$rule_ref->{fail}{$layer} = $coords ;

i did that as it seems you are using the same coord stuff. if not,
create a new anon ref with the values you want. there is definitely
redundancy there that can be removed but i won't say exactly what it is
as i don't know your real data structure needs. my gut feeling is that
you are overdesigning this and it is more complex than you need.

uri
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,201
Messages
2,571,048
Members
47,647
Latest member
NelleMacy9

Latest Threads

Top