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.
use Util::Columns;
my @list = <DATA>;
chomp @list;
my $columns = get_columns(7, \@list); # why take another step to get a
+n integer?
# 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;
my $row;
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
+ion> <tfoot>
<abbr> <col> <figcaption> <input> <ol> <sele
+ct> <th>
<address> <colgroup> <figure> <ins> <optgroup> <shad
+ow> <thead>
<area> <content> <footer> <kbd> <option> <slot
+> <time>
<article> <data> <form> <label> <output> <smal
+l> <title>
<aside> <datalist> <h1> <legend> <p> <sour
+ce> <tr>
<audio> <dd> <h2> <li> <param> <span
+> <track>
<b> <del> <h3> <link> <pre> <stro
+ng> <u>
<base> <details> <h4> <main> <progress> <styl
+e> <ul>
<bdi> <dfn> <h5> <map> <q> <sub>
+ <var>
<bdo> <dialog> <h6> <mark> <rp> <summ
+ary> <video>
<blockquote> <div> <head> <menu> <rt> <sup>
+ <wbr>
<br> <dl> <header> <menuitem> <rtc> <tabl
+e>
<button> <dt> <hgroup> <meta> <ruby> <tbod
+y>
<canvas> <element> <hr> <meter> <s> <td>
<caption> <em> <html> <nav> <samp> <temp
+late>
<cite> <embed> <i> <noscript> <script> <text
+area>
No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
Lady Aleena
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:
- 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
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|