Path: utzoo!news-server.csri.toronto.edu!rutgers!ucsd!ucbvax!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal L. Schwartz) Newsgroups: comp.lang.perl Subject: Re: SOURCE: lg -list groups Keywords: group Message-ID: <1991Mar14.225605.29822@iwarp.intel.com> Date: 14 Mar 91 22:56:05 GMT References: <6918@mitel> Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal L. Schwartz) Distribution: comp Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 45 In-Reply-To: lalonde@mitel ( iccad) In article <6918@mitel>, lalonde@mitel ( iccad) writes: [some code] Argh. Repeat after me: $foo or $foo[] or $foo{} gives me a single value; @foo or @foo[] or @foo{} gives me an array of values. It just happens that in all the contexts that you used the array refs, you got away with it. But someday, you would have gotten burned, and blamed the language. And I didn't go over your program with a fine-toothed comb, but the for loop with all the array-refs had me cringe enough to post this "how to think in Perl" response... | # If I was a real perl programmer I'd use a "format" wouldn't I? | 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];} ################################################## $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"; ################################################## There... and it'll probably run a half-a-millisecond faster too. # note the number of dots in each (..) below... print reverse"er,k haclr Perst anotheJu"=~/(...)(.)(....)(.)(.....)(.........)(..)/ -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Intel: putting the 'backward' in 'backward compatible'..."====/