On Sun, Nov 04, 2001 at 12:18:38PM -0800, Dave Storrs wrote: > > > On Sun, 4 Nov 2001, Gary L. Armstrong wrote: > > > I am amazed. How does someone figure out that you can do this sort of thing? > > > > chomp($value[++$i] = <STDIN>); > > > > I mean, $value[++$i]? That really works? Crazy. [...] > > > Well, that's mostly a C-style issue (and yes, it is crazy). C > programmers, for some bizarre reason, are convinced that there is a > tremendous shortage of whitespace in the world, and so, rather than > contribution to the death of the Old Growth Whitespace forests, they will > go to incredible lengths to jam things onto one line. Personally, I have > this thing for clarity. In my not-even-marginally-humble opinion, a line > of code should do one thing and one thing only (ok, sometimes I stretch a > point and do two things, if it is efficient and idiomatic). In > particular, I have always despised the "increment a variable inside an > array index" idiom in C. Therefore, I would have written it as: > > <STDIN>; > chomp; > $i++; > $value[$i] = $_; > > Some people say "Oh no! Look at that! You took up 4 lines where only 1 > was needed! Shame on you! Gasp, horror, collapse in revulsed > convulsions." To which I shrug. They always thank me later, when they > need to maintain my code.
Unfortunately, your code doesn't do the same as the original, however clear it is. If we're chucking opinions around, I think the first line is pretty clear to anyone who has programmed Perl for a while. I'd entertain arguments for breaking out the increment, if $i was used elsewhere, but if you're looking to clarify the code I'd probably want to get rid of $i altogether and use the much more idiomatic push function. Incidentally, I think the use of constructs like $value[++$i] is usually more to save cpu time rather than whitespace. [ Insert standard quote about premature optimisation here. ] > Rant mode off. We know return you to your regularly scheduled list. You call that a rant? Here's my prime number generator: perl -e 'print"@{[grep{(1x$_)!~/^(11+?)\1+$/}2..shift||1e2]}\n"' Get your teeth into that ;-) -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]