thekestrel has asked for the wisdom of the Perl Monks concerning the following question:
I'm playing with an 'array of hashes of arrays' and having some problems with data manipulation and was wondering if there might be some incite from above to help out...
sub AddConnection { my ($from, $to) = @_; for $l ( @list ) { if ( $l->{"name"} eq $from ) { push @{$l->{"outputs"}}, $to; } if ( $l->{"name"} eq $to ) { push @{$l->{"inputs"}}, $from; } } } sub AddRandomConnection { my @arr; my $i = scalar(@inputlist); print "we have $i elements to choose from\n"; my $rand_i = int(rand($i)); my $from = $inputlist[$rand_i]; print "we picked $rand_i : $from\n"; my $o = scalar(@inputlist); print "we have $i elements to choose from\n"; my $rand_o = int(rand($o)); my $to = $outputlist[$rand_o]; print "we picked $rand_o : $to\n"; #TODO: need to make sure you can't come to and from same node for $l ( @list ) { if ( $l->{"name"} eq $from ) { push @{$l->{"outputs"}}, $to; } if ( $l->{"name"} eq $to ) { push @{$l->{"inputs"}}, $from; } } }
Edit by castaway - Added readmore tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Array of hashes of Arrays
by dragonchild (Archbishop) on Feb 21, 2005 at 16:14 UTC | |
by thekestrel (Friar) on Feb 21, 2005 at 16:53 UTC | |
by dragonchild (Archbishop) on Feb 21, 2005 at 16:57 UTC | |
by thekestrel (Friar) on Feb 21, 2005 at 21:10 UTC | |
by thekestrel (Friar) on Feb 21, 2005 at 17:11 UTC | |
|
Re: Array of hashes of Arrays
by phaylon (Curate) on Feb 21, 2005 at 16:50 UTC | |
by thekestrel (Friar) on Feb 21, 2005 at 17:09 UTC |