Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!att!tut.cis.ohio-state.edu!uc!cs.umn.edu!cybrspc!roy From: roy%cybrspc@cs.umn.edu (Roy M. Silvernail) Newsgroups: comp.lang.perl Subject: Re: $# question Message-ID: Date: 24 Nov 90 00:56:16 GMT References: <109132@convex.convex.com> Organization: Villa CyberSpace, Minneapolis, MN Lines: 38 tchrist@convex.COM (Tom Christiansen) writes: > Just don't do this: > > for ($i = $[; $i <= $#a; $i++) { > $a[$i] = .... > } > > when this is there begging to be used: > > foreach (@a) { > # now access each element (by reference) as $_ > # which is usually implicit anyway > } (got me another trick... thanks!) OK, now consider the following fragment: for($x=0;$x<$#foo;$x++) { @aa = split(/\\/,@foo[$x]); @bb = split(/\\/,@foo[$x+1]); # forward array reference $foo[$x] = '' if $bb[$#bb - 1] ne $aa[$#aa - 1]; } Is there a spiffy Perl Way to handle the forward reference in each iteration without the explicit variable-controlled loop? (or have I happened upon the occasional exception that demands the for() construct?) (I'll bet a lot of this is in 'The Book'... guess what I'm getting _me_ for Christmas) Thanks for the expert guidance. -- Roy M. Silvernail |+| roy%cybrspc@cs.umn.edu |+| #define opinions ALL_MINE; main(){float x=1;x=x/50;printf("It's only $%.2f, but it's my $%.2f!\n",x,x);} "This is cyberspace." -- Peter da Silva :--: "...and I like it here!" -- me