in reply to Re: 'ls -C' column style
in thread 'ls -C' column style
Thanks for this; given the number of ways of doing:
I'm looking forward (perhaps unwisely) to being able to define an infix ⌈...⌉ operator for ceiling().$pl = int $pl + 1 if $pl != int $pl;
In general that line isn't a safe way of getting a ceiling, since it relies on equality testing of a floating point number; in this case though it would be dangerous only if the list of items were so large as to be impractical to display so it isn't really a problem. For generality I prefer the approach taken in some of the other examples above, effectively:
.. and I suspect you avoided this only because you were using ++$c within the expression - I'd have preferred:sub ceildiv { my($num, $div) = @_; return int(($num + $div - 1) / $div); }
++$c; $pl = int((@files + $c - 1)/$c);
Note that your approach of varying only the number of columns does miss some optimal solutions; for example, with $width = 20, $spacer = 2 you output the results in a single column even though the last 12 items could fit into a second column ('SDBM_File' being the last item that can't fit).
Hugo
|
|---|