Just because something works does not mean it is useful, good, or right. There are very few people would find a number as a word useful, but an integer is very useful. So making the return of an integer the default might lead to a few people using this little subroutine possibly. I've given an example below of what it does, and to show why it is more useful to return an integer by default.
my @list = <DATA>;
my $columns = get_columns(7, \@list); # why take another step to get a
# If you don't add 1 to the result of the division below,
# you will get an additional column.
my $splicer = (scalar(@list) / $columns) + 1;
push @$row, join("\n", splice(@list, 0, $splicer)) while @list;
# then print the row however you like
This is what I got from a list of html elements. If the list had fewer than 49 items, the there would have been 6 columns. (I have been working a lot with html elements lately, so they are on my mind.)
<a> <code> <fieldset> <img> <object> <sect
<abbr> <col> <figcaption> <input> <ol> <sele
<address> <colgroup> <figure> <ins> <optgroup> <shad
<area> <content> <footer> <kbd> <option> <slot
<article> <data> <form> <label> <output> <smal
<aside> <datalist> <h1> <legend> <p> <sour
<audio> <dd> <h2> <li> <param> <span
<b> <del> <h3> <link> <pre> <stro
<base> <details> <h4> <main> <progress> <styl
<bdi> <dfn> <h5> <map> <q> <sub>
<bdo> <dialog> <h6> <mark> <rp> <summ
<blockquote> <div> <head> <menu> <rt> <sup>
<br> <dl> <header> <menuitem> <rtc> <tabl
<button> <dt> <hgroup> <meta> <ruby> <tbod
<canvas> <element> <hr> <meter> <s> <td>
<caption> <em> <html> <nav> <samp> <temp
<cite> <embed> <i> <noscript> <script> <text
No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||