[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[FWP] Interleaving arrays



I pull a sorted list of "categories out" of DBD::Pg and I need to
display it in a two-column HTML table. However, HTML tables are
arranged by rows so the order went across, rather than going down the
left column then down the right column. Since the HTML rendering
happens in another module far away, and the array is small (<50 array
refs), I just reordered the array ... like this:

   @cats = @cats[map (($_/2 + ($_ % 2) * $#cats/2), 0..$#cats)];

Now the page layout has changed and I only need it in one column (doh!
*slap* my client upside the head)

I'm posting the code here so I don't lose it. One obvious optimization
is to not recalculate $#cats/2 inside the map. Anyone else have
comments?

Tom

-- 
--    Tom Rathborne    tomr@aceldama.com
--                     http://www.aceldama.com/~tomr/
--    "I seem to be having tremendous difficulty with my life-style."

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe