Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.jpl.nasa.gov (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: SOURCE: lg -list groups Keywords: group Message-ID: <1991Mar14.235553.21241@jpl-devvax.jpl.nasa.gov> Date: 14 Mar 91 23:55:53 GMT References: <6918@mitel> <1991Mar14.225605.29822@iwarp.intel.com> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Distribution: comp Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 65 : In article <6918@mitel>, lalonde@mitel ( iccad) writes: : | for( $j=0; $j <= $#t; $j+=6) { : | printf "%-8s %-8s %-8s %-8s %-8s %-8s\n",@t[$j],@t[$j+1],@t[$j+2],@t[$j+3],@t[$j+4],@t[$j+5];} If I were going to write the loop that way, I'd write the printf as printf "%-8s %-8s %-8s %-8s %-8s %-8s\n", @t[$j..$j+5]; In article <1991Mar14.225605.29822@iwarp.intel.com> merlyn@iwarp.intel.com (Randal L. Schwartz) writes: : ################################################## : $j = 0; # column number... 0 is new, 1..6 normally : for (@t) { : unless ($j++ == 0) { : if ($j > 6) { : print "\n"; $j = 1; : } else { : print " "; : } : } : printf "%-8s", $_; : } : print "\n"; : ################################################## Seems a bit long. How 'bout: $j = 0; for (@t) { printf "%-8s%s", $_, $j++ < @t && $j % 6 ? ' ' : "\n"; } or $j = 0; for (@t) { print $_, $j++ < @t && $j % 6 ? ' ' x (9-length) : "\n"; } or $n = " \n" x (@t / 6 + 1); substr($n,@t-1) = "\n"; $n = reverse $n; for (@t) { printf "%-8s%s", $_, chop($n); } or $n = (' ' x 71 . "\n") x ($#t / 6 + 1); $j = 0; for (@t) { substr($n,$j,length) = $_; $j += 9; } print $n; or, if you don't mind destroying @t: for (@t) {$_ .= ' ' x (8-length);} while (@x = splice(@t,0,6)) { print "@x\n"; } However, like iccad said, maybe you want a format: format STDOUT = @<<<<<<< @<<<<<<< @<<<<<<< @<<<<<<< @<<<<<<< @<<<<<<<~~ shift t, shift t, shift t, shift t, shift t, shift t . write; That seems quite readable, no? Redundancy is not always an evil. Larry