File size distribution: Difference between revisions

m
→‎{{header|REXX}}: added/changed whitespace and comments, simplified the inner DO loop by eliding the use of SELECT.
(Added Perl example)
m (→‎{{header|REXX}}: added/changed whitespace and comments, simplified the inner DO loop by eliding the use of SELECT.)
Line 457:
parse arg ds . /*obtain optional argument from the CL.*/
parse source . . path . /* " the path of this REXX program.*/
fID= substr(path, 1 + lastpos('\', path) ) /* " the filename and the filetype.*/
parse var fID fn '.' /* " just the pure filename of pgm.*/
sw=max(79, linesize() - 1) /* " terminal width (linesize) - 1.*/
Line 463:
'DIR' ds '/s /-c /a-d >' work /*do (DOS) DIR cmd for a data structure*/
call linein 0, 1 /*open output file, point to 1st record*/
maxL= 0; @.= 00; g=0 0 /*max len size; log array; # good recs.*/
$=0 /*$: total bytes used by files found. */
do while lines(work)\==0; _= linein(work) /*process the data in the DIR work file*/
if left(_, 1)==' ' then iterate /*Is the record not legitimate? Skip. */
parse upper var _ . . sz . /*uppercase suffix*/
if \datatype(sz,'W') then do; #= left(sz, length(sz) - 1) /*SZ has a suffix?*/
if \datatype(#, 'N') then iterate /*Meat ¬ numeric? */
sz= # * 1024 ** pos( right(sz, 1), 'KMGTPEZYXWVU') / 1
end /* [↑] use suffix*/
$= $ + sz /*keep a running total for the filesize*/
if sz==0 then L=0 0 /*handle special case for an empty file*/
else L= length(sz) /*obtain the length of filesize number.*/
g= g + 1 /*bump the counter of # of good records*/
maxL= max(L, maxL) /*get max length filesize for alignment*/
@.L= @.L + 1 /*bump counter of record size category.*/
end /*j*/ /* [↑] categories: split by log ten.*/
 
Line 485:
mC=0 /*mC: the maximum count for any range.*/
do t=1 to 2 /*T==1 is used to find the max count.*/
do k=0 to maxL; mC= max(mC, @.k); if t==1 then iterate /*1st pass? */
selectif k==0 then y= center('zero', length( word(hdr, 1) ) )
when k==0 then else y= center('zero10^'left(k-1,2) length("──► word10^"left(hdrk, 12) ) )'-1'
otherwise y= '10^'left(k-1,2) "──► 10^"left(k,2) '-1'
end /*select*/
say y || right( commas(@.k), 11) copies('─', max(1, (@.k / mC * sw % 1) - LHdr) )
end /*k*/