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

Re: finding all combinations

by lima1 (Curate)
on Jan 13, 2008 at 23:20 UTC ( #662226=note: print w/replies, xml ) Need Help??


in reply to finding all combinations

use strict; use warnings; my @array1 = (1,2,3); my @array2 = (7,8); my @array3 = (1,5,23,3); sub to_string { return '{' . join(q{,}, @_) . '}'; } print "$_ " while glob to_string(@array1) . q{-} . to_string(@array2) +. q{-} . to_string(@array3); __END__ 1-7-1 1-7-5 1-7-23 1-7-3 1-8-1 1-8-5 1-8-23 1-8-3 2-7-1 2-7-5 2-7-23 2 +-7-3 2-8-1 2-8-5 2-8-23 2-8-3 3-7-1 3-7-5 3-7-23 3-7-3 3-8-1 3-8-5 3- +8-23 3-8-3
Update: Ah nice jwkrahn :) Did not know $".

Replies are listed 'Best First'.
Re^2: finding all combinations
by jwkrahn (Monsignor) on Jan 14, 2008 at 01:05 UTC
    Or more succinctly:
    my @array1 = (1,2,3); my @array2 = (7,8); my @array3 = (1,5,23,3); $" = ','; print "$_ " while glob "{@array1}-{@array2}-{@array3}";

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2020-10-30 14:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (280 votes). Check out past polls.

    Notices?