{"id":16,"date":"2011-05-19T22:23:58","date_gmt":"2011-05-19T22:23:58","guid":{"rendered":"http:\/\/alexboisvert.com\/musings\/?p=16"},"modified":"2011-05-20T16:30:38","modified_gmt":"2011-05-20T16:30:38","slug":"deprecated-perl","status":"publish","type":"post","link":"https:\/\/alexboisvert.com\/musings\/2011\/05\/19\/deprecated-perl\/","title":{"rendered":"Deprecated perl"},"content":{"rendered":"<p><a href=\"http:\/\/xkcd.com\/353\/\">Perl, I&#8217;m leaving you.<\/a><\/p>\n<p>I changed my GMail status to this today and I thought I would give a few words about why.  I wanted to go through my Scrabble word list to find five-letter words in which the 3rd and 4th letters were the same, and which became new words when read backward.  At first I modified a stock perl script of mine to do it, and then I wondered how easy it would be in Python.  So I took a few minutes and came up with this:<\/p>\n<p>[python]<br \/>\n#!\/usr\/bin\/python<\/p>\n<p>fid = open(&#8216;scrabble.txt&#8217;,&#8217;r&#8217;)<br \/>\ndict = [x.rstrip(&#8216;\\r\\n&#8217;) for x in fid.readlines()]<br \/>\nfid.close()<br \/>\nmywords = [x for x in dict if len(x) == 5 and \\<br \/>\nx[2] == x[3] and x[::-1] in dict]<br \/>\nprint mywords<br \/>\n[\/python]<br \/>\n(Edited to fix a minor error)<\/p>\n<p>How awesome is that?  Look at how short, clean, and readable it is!  The only slightly tricky part is the <\/p>\n<pre>x[::-1]<\/pre>\n<p> bit that reverses the string x.  So from now on, all my (new) scripting will be in Python.  This includes, by the way, the <a href=\"http:\/\/alexboisvert.com\/roman\">Roman numeral clue<\/a> page that&#8217;s just gone up.  So there&#8217;s that, too.<\/p>\n<p><strong>Update:<\/strong> here&#8217;s Joon&#8217;s perl code to do the same thing.<br \/>\n[perl]<br \/>\n#!\/usr\/bin\/perl<br \/>\nuse strict;<\/p>\n<p>my %dict;<br \/>\nopen DICT, &#8220;scrabble.txt&#8221;;<br \/>\nwhile (<DICT>) { chomp; $dict{$_} = 1; }<br \/>\nclose DICT;<br \/>\nfor (sort keys %dict) { print &#8220;$_\\n&#8221; if (\/^..(.)\\1.$\/ &#038;&#038; $dict{reverse($_)}); }<br \/>\n[\/perl]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Perl, I&#8217;m leaving you. I changed my GMail status to this today and I thought I would give a few words about why. I wanted to go through my Scrabble word list to find five-letter words in which the 3rd &hellip; <a href=\"https:\/\/alexboisvert.com\/musings\/2011\/05\/19\/deprecated-perl\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-16","post","type-post","status-publish","format-standard","hentry","category-coding"],"_links":{"self":[{"href":"https:\/\/alexboisvert.com\/musings\/wp-json\/wp\/v2\/posts\/16","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alexboisvert.com\/musings\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alexboisvert.com\/musings\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alexboisvert.com\/musings\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/alexboisvert.com\/musings\/wp-json\/wp\/v2\/comments?post=16"}],"version-history":[{"count":9,"href":"https:\/\/alexboisvert.com\/musings\/wp-json\/wp\/v2\/posts\/16\/revisions"}],"predecessor-version":[{"id":26,"href":"https:\/\/alexboisvert.com\/musings\/wp-json\/wp\/v2\/posts\/16\/revisions\/26"}],"wp:attachment":[{"href":"https:\/\/alexboisvert.com\/musings\/wp-json\/wp\/v2\/media?parent=16"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alexboisvert.com\/musings\/wp-json\/wp\/v2\/categories?post=16"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alexboisvert.com\/musings\/wp-json\/wp\/v2\/tags?post=16"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}