{"id":48,"date":"2009-01-14T22:00:00","date_gmt":"2009-01-14T22:00:00","guid":{"rendered":"https:\/\/karwin.com\/blog\/index.php\/2009\/01\/14\/best-perl-script-ever\/"},"modified":"2020-02-19T22:57:01","modified_gmt":"2020-02-19T22:57:01","slug":"best-perl-script-ever","status":"publish","type":"post","link":"https:\/\/karwin.com\/blog\/index.php\/2009\/01\/14\/best-perl-script-ever\/","title":{"rendered":"Best. Perl Script. Ever."},"content":{"rendered":"<p>A user recently <a href=\"http:\/\/stackoverflow.com\/questions\/303876\/what-is-your-best-programming-experience\">asked<\/a>:<\/p>\n<blockquote><p>What has been your best programming experience so far?<\/p><\/blockquote>\n<p>The most successful program I&#8217;ve ever written was this Perl script:<\/p>\n<pre><code><span style=\"font-family: courier new;\">map<\/span><span style=\"font-family: courier new;\">((<\/span><span style=\"font-family: courier new;\">$r<\/span><span style=\"font-family: courier new;\">=<\/span><span style=\"font-family: courier new;\">$_<\/span><span style=\"font-family: courier new;\">,<\/span><span style=\"font-family: courier new;\">map<\/span><span style=\"font-family: courier new;\">((<\/span><span style=\"font-family: courier new;\">$y<\/span><span style=\"font-family: courier new;\">=<\/span><span style=\"font-family: courier new;\">$r<\/span><span style=\"font-family: courier new;\">-<\/span><span style=\"font-family: courier new;\">$_<\/span><span style=\"font-family: courier new;\">\/<\/span><span style=\"font-family: courier new;\">3<\/span><span style=\"font-family: courier new;\">,<\/span><span style=\"font-family: courier new;\">$l<\/span><span style=\"font-family: courier new;\">[<\/span><span style=\"font-family: courier new;\">24<\/span><span style=\"font-family: courier new;\">-<\/span><span style=\"font-family: courier new;\">$r<\/span><span style=\"font-family: courier new;\">]\n.=(<\/span><span style=\"font-family: courier new;\">' '<\/span><span style=\"font-family: courier new;\">,<\/span><span style=\"font-family: courier new;\">'@'<\/span><span style=\"font-family: courier new;\">)[<\/span><span style=\"font-family: courier new;\">$y<\/span><span style=\"font-family: courier new;\">**<\/span><span style=\"font-family: courier new;\">2<\/span><span style=\"font-family: courier new;\">-<\/span><span style=\"font-family: courier new;\">20<\/span><span style=\"font-family: courier new;\">*<\/span><span style=\"font-family: courier new;\">$y<\/span><span style=\"font-family: courier new;\">+(<\/span><span style=\"font-family: courier new;\">$_<\/span><span style=\"font-family: courier new;\">**<\/span><span style=\"font-family: courier new;\">2<\/span><span style=\"font-family: courier new;\">)\/<\/span><span style=\"font-family: courier new;\">3<\/span><span style=\"font-family: courier new;\">&lt;<\/span><span style=\"font-family: courier new;\">0<\/span><span style=\"font-family: courier new;\">]),(<\/span><span style=\"font-family: courier new;\">0..30<\/span><span style=\"font-family: courier new;\">)),),(<\/span><span style=\"font-family: courier new;\">0..24<\/span><span style=\"font-family: courier new;\">));<\/span><span style=\"font-family: courier new;\">\n<\/span><span style=\"font-family: courier new;\">print<\/span><span style=\"font-family: courier new;\"> join<\/span><span style=\"font-family: courier new;\">(<\/span><span style=\"font-family: courier new;\">\"\\n\"<\/span><span style=\"font-family: courier new;\">,<\/span><span style=\"font-family: courier new;\"> map<\/span><span style=\"font-family: courier new;\">(<\/span><span style=\"font-family: courier new;\">reverse<\/span><span style=\"font-family: courier new;\">(<\/span><span style=\"font-family: courier new;\">$_<\/span><span style=\"font-family: courier new;\">).<\/span><span style=\"font-family: courier new;\">$_<\/span><span style=\"font-family: courier new;\">,<\/span><span style=\"font-family: courier new;\"> @l<\/span><span style=\"font-family: courier new;\">)),<\/span> <span style=\"font-family: courier new;\">\"\\n\"<\/span><span style=\"font-family: courier new;\">;<\/span>\n<\/code><\/pre>\n<p>I wrote this for a woman I was dating in 2001. Writing a Perl script for my girlfriend is not as geeky as it sounds, at least in this case. She&#8217;s also a software developer, and she was taking a Perl class at the time.<\/p>\n<p>I consider this script a great success because she married me in 2007!<\/p>\n<p>I&#8217;ll leave it as an exercise for the reader to run the script in a console window and see its output (I promise it&#8217;s not a Trojan Horse or any other kind of evil trick).<\/p>\n<p>I&#8217;m posting to my blog the questions I&#8217;ve answered on StackOverflow, which earned the &#8220;Good Answer&#8221; badge. This was based on my answer to &#8220;<a href=\"http:\/\/stackoverflow.com\/questions\/303876\/what-is-your-best-programming-experience#303992\">What is your best programming experience?<\/a>&#8220;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A user recently asked: What has been your best programming experience so far? The most successful program I&#8217;ve ever written was this Perl script: map(($r=$_,map(($y=$r-$_\/3,$l[24-$r] .=(&#8216; &#8216;,&#8217;@&#8217;)[$y**2-20*$y+($_**2)\/3&lt;0]),(0..30)),),(0..24)); print join(&#8220;\\n&#8221;, map(reverse($_).$_, @l)), &#8220;\\n&#8221;; I wrote this for a woman I was dating in 2001. Writing a Perl script for my girlfriend is not as geeky as [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[24],"tags":[],"class_list":["post-48","post","type-post","status-publish","format-standard","hentry","category-perl"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pawgV7-M","jetpack-related-posts":[],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/karwin.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/48","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/karwin.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/karwin.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/karwin.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/karwin.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=48"}],"version-history":[{"count":0,"href":"https:\/\/karwin.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/48\/revisions"}],"wp:attachment":[{"href":"https:\/\/karwin.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=48"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/karwin.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=48"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/karwin.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=48"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}