On 2007-01-10 15:06:56 -0800, Ofer Nave wrote: > Henri Asseily wrote: > >Take the example of the pod: > >$DATABASE::conf{'test'} = { > > max_retries => 2, > > db_stack => [ > > [ 'dbi:Sybase:server=prod1;database=test', 'user1', 'pass1', $attrib ], > > [ 'dbi:Sybase:server=prod2;database=test', 'user2', 'pass2', $attrib ], > > [ 'dbi:Sybase:server=prod3;database=test', 'user3', 'pass3', $attrib ], > > ], ... [...] > >Here's a complex example: > >In the case above, say you have 20 children for those 3 databases. > >The different stack permutations are: > >1: prod1,prod2,prod3 > >2: prod1,prod3,prod2 > >3: prod2,prod1,prod3 > >4: prod2,prod3,prod1 > >5: prod3,prod1,prod2 > >6: prod3,prod2,prod1 > >Either dynamically or statically create these 6 permutations and put them in > >@all_db_stacks: [...] > > Couldn't an option be added as an alternative to db_stack that indicates a > desire for random ordering, thereby eliminating the need to precreate all > possible permutations? I'm imaging something like this (modified version of > your example): > > $DATABASE::conf{'test'} = { > max_retries => 2, > db_pool => [ > [ 'dbi:Sybase:server=prod1;database=test', 'user1', 'pass1', $attrib ], > [ 'dbi:Sybase:server=prod2;database=test', 'user2', 'pass2', $attrib ], > [ 'dbi:Sybase:server=prod3;database=test', 'user3', 'pass3', $attrib ], > ], ...
How about just using shuffle from the standard module List::Util? use List::Util qw(shuffle); $DATABASE::conf{'test'} = { max_retries => 2, db_stack => [ shuffle ( [ 'dbi:Sybase:server=prod1;database=test', 'user1', 'pass1', $attrib ], [ 'dbi:Sybase:server=prod2;database=test', 'user2', 'pass2', $attrib ], [ 'dbi:Sybase:server=prod3;database=test', 'user3', 'pass3', $attrib ], ) ], ... hp -- _ | Peter J. Holzer | If I wanted to be "academically correct", |_|_) | Sysadmin WSR | I'd be programming in Java. | | | [EMAIL PROTECTED] | I don't, and I'm not. __/ | http://www.hjp.at/ | -- Jesse Erlbaum on dbi-users
pgpAXpSF4OodH.pgp
Description: PGP signature