<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>woft.am - Latest Comments in 10 Perl One Liners to Impress(?) Your Friends</title><link>http://woftam.disqus.com/</link><description></description><atom:link href="http://woftam.disqus.com/10_perl_one_liners_to_impress_your_friends/latest.rss" rel="self"></atom:link><language>en</language><lastBuildDate>Mon, 06 Jun 2011 18:07:36 -0000</lastBuildDate><item><title>Re: 10 Perl One Liners to Impress(?) Your Friends</title><link>http://woft.am/perl/2011/06/05/10-perl-one-liners-to-impress-your-friends/#comment-219516249</link><description>&lt;p&gt;the fastest thing is to set the hash value to undef which doesn't have ref counting, and is an internal pointer to SV_UNDEF, and to use exists(). However, that's reasonably more ugly. And, the point is you can at least stay O(n) with a hash, non-set array intersections are always O(n**2) which gets bad fast.&lt;/p&gt;

&lt;p&gt;You can use all of the suggestions, also this rule is universal. One loop is always better.&lt;/p&gt;

&lt;p&gt;Not: &lt;br&gt;say for grep { $tweet =~ /\b$_\b/ } @wordlist;&lt;/p&gt;

&lt;p&gt;But:&lt;br&gt;for (@wordlist) { say if /\b$_\b/ }&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Evan Carroll</dc:creator><pubDate>Mon, 06 Jun 2011 18:07:36 -0000</pubDate></item><item><title>Re: 10 Perl One Liners to Impress(?) Your Friends</title><link>http://woft.am/perl/2011/06/05/10-perl-one-liners-to-impress-your-friends/#comment-218815667</link><description>&lt;p&gt;I used map because it's a direct analog to the Scala solution in the original article - then tacked a 'say for' at the beginning and didn't think about it. D'oh! Same deal with using smart-match rather than a hash lookup (because other languages have an 'in' operator). Thanks, though! Do you mind if I add your improvements to the article?&lt;/p&gt;

&lt;p&gt;Btw, checking 'exists $tweet_words{$_}' seems to be about 5-10% faster than not using exists on my machine (Perl 5.10.1 on Ubuntu 10.04).&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">rjh29</dc:creator><pubDate>Sun, 05 Jun 2011 20:16:32 -0000</pubDate></item><item><title>Re: 10 Perl One Liners to Impress(?) Your Friends</title><link>http://woft.am/perl/2011/06/05/10-perl-one-liners-to-impress-your-friends/#comment-218583555</link><description>&lt;p&gt;Most of these aren't one liners, they're just expressions. Most of them can also be written better...&lt;/p&gt;

&lt;p&gt;Here you're iterating twice for no reason.. &lt;br&gt;perl -E 'say for map { $_ * 2 } 1..10'&lt;br&gt;Just do, -E'say $_*2 for 1..10'&lt;/p&gt;

&lt;p&gt;Your algo for checking if a word exists in a string is slow. If one liners don't matter...&lt;br&gt;    my %tweet_words;&lt;br&gt;    $tweet_words{$_}=1 for split /\W/, $tweet;&lt;br&gt;    say $tweet_words ? "found [$_]" : "not found [$_"] for @wordlist;&lt;/p&gt;

&lt;p&gt;List::Util is nice, but for one liners this will achive the same effect.&lt;br&gt;    perl -00E'my $foo = &amp;lt;&amp;gt;; print $foo' foobar.txt&lt;/p&gt;

&lt;p&gt;Again, you seem to be hellset on using `for` and `map`... you should pick.&lt;br&gt;    say for map { "Happy Birthday to " . ($_ == 2 ? "dear Name" : "you") } 0..3;&lt;br&gt;    say "Happy Birthday to " . ($_ == 2 ? "dear Name" : "you") for 0..3;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Evan Carroll</dc:creator><pubDate>Sun, 05 Jun 2011 13:04:30 -0000</pubDate></item><item><title>Re: 10 Perl One Liners to Impress(?) Your Friends</title><link>http://woft.am/perl/2011/06/05/10-perl-one-liners-to-impress-your-friends/#comment-218515551</link><description>&lt;p&gt;It's interesting that so many of your examples are numeric but you haven't tried "use PDL;", which loads a scientific grade numerical processing package.   PDL minmax is between 30 and 150 times faster than List::MoreUtils::minmax (it gets the gain by working on traditional structured arrays of numbers rather than on Perl lists of polymorphous scalars).&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Craig DeForest</dc:creator><pubDate>Sun, 05 Jun 2011 09:23:09 -0000</pubDate></item></channel></rss>
