NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.
All the Perl that's Practical to Extract and Report
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
Lines of code? (Score:1)
while () { print unless
Of course, you could match his argument conventions precisely, but why bother? This form is the normal Perl way to do it, and the author's Perl and Java arguments were already different.
I haven't benchmarked this one-liner, but I bet it's faster than the author's Perl version, and likely faster than the Java code as well. It might be a shade faster to drop the outermost parens, and avoid capturing with (?:...) and avoid an alternation by replacing 9|18|29 with 2?9|18, but these would come at the expense of readability and might not make a noticable performance impact.
Also, that one line of Perl code took me only about 2 minutes to write (slowed down slightly be double-checking the (?i:...) construct). I'm betting that 100 lines of Java code took quite a bit longer to write and debug, and it's harder to maintain 100 lines of code than one. In real life, I'd probably have used a
As far as I'm concerned, Perl's "home turf" includes being efficient for the programmer to write programs. Sometimes, highly-optimized runtime is important, but optimizing programming time is frequently more valuable. Even so, short Perl programs like this often have hard-to-beat runtimes if written well, so you can often have your cake and eat it too...
Deven
"Simple things should be simple, and complex things should be possible." - Alan Kay
Reply to This
Re:Lines of code? (Score:1)
As someone said somewhere (petdance iirc), when making optimized solutions, test. It's something a lot of people seem to not be doing in this thread (either here or in davorg's journal). If you're going to make it more efficient, you might as well make it produce the same results.
At work, I produced a shiny new version of a previous routine. I couldn't really benchmark them though: the previous version processed much less data due to a bug in its impleme
---ict / Spoon
Re:Lines of code? (Score:1)
Unfortunately, when I put them back in, I put the opening paren after the ^ (force of habit) when that's not what I meant. My bad!
I also lost the <> operator inside the while (), while we're being pedantic.
Deven
"Simple things should be simple, and complex things should be possible." - Alan Kay