jettero has asked for the wisdom of the Perl Monks concerning the following question:
You guys, I'm looking for the syntactically coolest looking way to build a list of lists from a list.
@a = (1,5,7,9,32,197,8,4,5); # (pretend this is dynamically generate +d) @b = map {[ $a[2*$_], $a[2*$_+1]||() ]} 0 .. int $#a/2;
Above is the best I'd come up with so far for generating @b, but I'm not sure it's the syntactically coolest possible way to do it. I'd also like to generalize it to a list of lists of size $l rather than always being $l=2.
This is a highly subjective problem and I'm already about responses.
-Paul
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Syntactically cool list of lists
by GrandFather (Saint) on Dec 20, 2006 at 21:14 UTC | |
by sauoq (Abbot) on Dec 20, 2006 at 22:30 UTC | |
by jettero (Monsignor) on Dec 20, 2006 at 21:23 UTC | |
|
Re: Syntactically cool list of lists
by BrowserUk (Patriarch) on Dec 20, 2006 at 22:29 UTC | |
|
Re: Syntactically cool list of lists
by Fletch (Bishop) on Dec 20, 2006 at 21:14 UTC | |
|
Re: Syntactically cool list of lists
by rhesa (Vicar) on Dec 20, 2006 at 21:41 UTC | |
by ikegami (Patriarch) on Dec 21, 2006 at 00:26 UTC | |
by jettero (Monsignor) on Dec 21, 2006 at 02:30 UTC | |
|
Re: Syntactically cool list of lists
by rir (Vicar) on Dec 21, 2006 at 01:32 UTC | |
|
Re: Syntactically cool list of lists
by sgifford (Prior) on Dec 21, 2006 at 04:05 UTC | |
by johngg (Canon) on Dec 21, 2006 at 10:02 UTC | |
by sgifford (Prior) on Dec 22, 2006 at 04:12 UTC | |
by TimToady (Parson) on Dec 22, 2006 at 17:42 UTC | |
|
Re: Syntactically cool list of lists
by shmem (Chancellor) on Dec 21, 2006 at 11:00 UTC | |
by johngg (Canon) on Dec 21, 2006 at 11:28 UTC | |
|
Re: Syntactically cool list of lists
by tsee (Curate) on Dec 22, 2006 at 11:46 UTC | |
|
Re: Syntactically cool list of lists
by druud (Sexton) on Dec 22, 2006 at 17:07 UTC |