<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-533407576171979325</id><updated>2012-01-31T22:44:16.183-08:00</updated><category term='screen'/><category term='module'/><category term='catalyst'/><category term='photo'/><category term='cpanp'/><category term='vim'/><category term='bash'/><category term='blog admin'/><category term='web'/><category term='mac'/><category term='perl'/><title type='text'>Code and Hacks</title><subtitle type='html'>Stuff I've stumbled on or figured out... mostly Perl, Linux, Mac and Cygwin.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://code-and-hacks.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/533407576171979325/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://code-and-hacks.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Mark</name><uri>http://www.blogger.com/profile/09695682449145009572</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='27' src='http://1.bp.blogspot.com/_3S63aFOwxrA/SfdpX4ggnSI/AAAAAAAAAcc/hMmQj6rMYUU/S220/103008-full-oil.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>13</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-533407576171979325.post-3508638312004912080</id><published>2010-04-12T09:04:00.000-07:00</published><updated>2010-04-12T09:04:49.825-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='screen'/><title type='text'>Setting the Terminal Title in Gnu Screen</title><content type='html'>&lt;p&gt;I often have multiple terminals open and screen running in each one. I then try to group all my work for a particular project in that terminal. While I am trying to limit the amount of multitasking and concentrate on one thing at a time, I might leave a terminal/screen session up for days and when I come back I can jump right back where I started.&lt;/p&gt;

&lt;p&gt;The downside to this is using &lt;code&gt;cmd-tab&lt;/code&gt; (or &lt;code&gt;alt-tab&lt;/code&gt; with &lt;a href='http://manytricks.com/witch/'&gt;Witch&lt;/a&gt;) gives me a list of several terminals each with the title &lt;code&gt;screen - bash - username&lt;/code&gt; or maybe &lt;code&gt;screen - vim -
username&lt;/code&gt;&amp;#8230; not very helpful. What I want is to set a name for each terminal and display it in the terminal&amp;#8217;s title. If I anticipate this before launching screen, I can accomplish it with &lt;code&gt;screen -t &amp;lt;My Title&amp;gt;&lt;/code&gt;. Once I am inside a session though, you need to change each window&amp;#8217;s title/name for this to work.&lt;/p&gt;

&lt;p&gt;After searching the web and a bunch of trial-and-error, I found a solution. The first part is pretty well documented. Changing the name for all windows and the default for new windows took quite a bit a tinkering.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Setup screen (via &lt;code&gt;.screenrc&lt;/code&gt;) to update your terminals title bar and include the name of the current window.&lt;/p&gt;

&lt;code&gt;&lt;pre class='brush: bash'&gt;# Add to .screenrc
termcapinfo xterm* &amp;#39;hs:ts=\E]0;:fs=\007:ds=\E]0;\007&amp;#39;
defhstatus &amp;quot;screen ^E (^Et) | $USER@^EH&amp;quot;
hardstatus off&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The escape string &lt;code&gt;^Et&lt;/code&gt; in the &lt;code&gt;defhstatus&lt;/code&gt; is converted into the current window&amp;#8217;s name/title.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Create a function to update the name of each screen window.&lt;/p&gt;

&lt;code&gt;&lt;pre class='brush: bash'&gt;# Add to .bashrc
# Set the title of a Terminal window
function settitle() {
 if [ -n &amp;quot;$STY&amp;quot; ] ; then         # We are in a screen session
  echo &amp;quot;Setting screen titles to $@&amp;quot;
  printf &amp;quot;\033k%s\033\\&amp;quot; &amp;quot;$@&amp;quot;
  screen -X eval &amp;quot;at \\# title $@&amp;quot; &amp;quot;shelltitle $@&amp;quot;
 else
  printf &amp;quot;\033]0;%s\007&amp;quot; &amp;quot;$@&amp;quot;
 fi
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You can change the name of the current window by pressing &lt;code&gt;Ctrl-a A&lt;/code&gt;, but we want to change the title for all the windows. &lt;code&gt;screen -X eval&lt;/code&gt; will execute each of its arguments in the current screen. The command &lt;code&gt;at \#
title&lt;/code&gt; will execute the &lt;code&gt;title&lt;/code&gt; command in all the windows (the &lt;code&gt;\&lt;/code&gt; before &lt;code&gt;#&lt;/code&gt; is required otherwise &lt;code&gt;#&lt;/code&gt; will be interpreted as the beginning of a comment). The &lt;code&gt;shelltitle&lt;/code&gt; command will ensure that any newly created windows use this title.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/533407576171979325-3508638312004912080?l=code-and-hacks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-and-hacks.blogspot.com/feeds/3508638312004912080/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://code-and-hacks.blogspot.com/2010/04/setting-terminal-title-in-gnu-screen.html#comment-form' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/533407576171979325/posts/default/3508638312004912080'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/533407576171979325/posts/default/3508638312004912080'/><link rel='alternate' type='text/html' href='http://code-and-hacks.blogspot.com/2010/04/setting-terminal-title-in-gnu-screen.html' title='Setting the Terminal Title in Gnu Screen'/><author><name>Mark</name><uri>http://www.blogger.com/profile/09695682449145009572</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='27' src='http://1.bp.blogspot.com/_3S63aFOwxrA/SfdpX4ggnSI/AAAAAAAAAcc/hMmQj6rMYUU/S220/103008-full-oil.jpg'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-533407576171979325.post-8637523731079330101</id><published>2010-04-02T06:57:00.000-07:00</published><updated>2010-04-02T07:33:53.221-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='web'/><title type='text'>Open Source Presentation Software</title><content type='html'>&lt;p&gt;I am thinking about giving a presentation at one of my local Perl Monger meetings. So as usual, I have spent a bunch of time toying with new tools rather than getting work done! Which tools: open source presentation creation software. I wanted something that would take a simple text file and easily create an attractive and easy to use presentation.&lt;/p&gt;

&lt;p&gt;Here is a quick summary of the options that I tried or looked into:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Vroom::Vroom - This is cool. If you like vim and aren&amp;#8217;t hung up on the output format it might be for you. I had some trouble getting the key-bindings to work, but I would guess it was a conflict with another vim plugin.&lt;/p&gt;

&lt;p&gt;Vroom can present right in vim or output to html. Both are pretty plain looking, but I didn&amp;#8217;t look into customizing the html output. I love that you can press &lt;code&gt;RR&lt;/code&gt; and run the code on the slide. The input is a custom format but it is pretty similar to markdown.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Pod::S5 - I really wanted to like this one&amp;#8211;it is written in Perl, uses a standard method input format, and it creates an HTML presentation. But I was hung up on a couple of things. While pod is great, it isn&amp;#8217;t nearly as easy to use as markdown, and the text slides just aren&amp;#8217;t that easy to read. Things like lists just take up too much room:&lt;/p&gt;

&lt;code&gt;&lt;pre class='brush: perl'&gt;=over 4

=item *

A Bullet

=item *

Another Bullet

=back&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That&amp;#8217;s just too much vertical whitespace.&lt;/p&gt;

&lt;p&gt;Second, the output is S5 which has been superseded by S6. The templates in S5 didn&amp;#8217;t really appeal to me and had some issues in my browser.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Spork / Spork::S5 - I had some trouble installing this, but eventually realized I just needed to install Kwiki::Cache first. The default themes are not particularly attractive, but again I didn&amp;#8217;t look into customizing the output. I do like that it automatically scales text. The ability to highlight sections of the text/code with underlining or colors sounds very cool. For example, this markup:&lt;/p&gt;

&lt;code&gt;&lt;pre class='brush: perl'&gt;.pretty.
 sub greet {
  print &amp;quot;Hello there\n&amp;quot;;
#             _______________
#              RRRRR
 }    
.pretty.&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Should underline and make &amp;#8220;Hello there&amp;#8221; red. I didn&amp;#8217;t test this, but according to the documentation it is &amp;#8220;coming soon&amp;#8221;.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;&lt;a href='http://slideshow.rubyforge.org/'&gt;Slide Show (S9)&lt;/a&gt; - I ended up settling on Slide Show. While I was biased toward a Perl solution, and this is written in Ruby, it definitely seemed the most mature and robust solution. (Maybe I&amp;#8217;ll end up learning a bit of Ruby as a side benefit.)&lt;/p&gt;

&lt;p&gt;Slide show can take either textile or markdown as input, it outputs S5 or S6, and has some nice (and simple) templates bundled. It will use any one of a number of markdown parsers so I am using Maruku which has some nice additions to the core markdown syntax (ie, add a css class declaration to an element).&lt;/p&gt;

&lt;p&gt;Installation was easy (once I googled for one error message):&lt;/p&gt;

&lt;code&gt;&lt;pre class='brush: bash'&gt;gem install slideshow
gem install ultraviolet
# got error: oniguruma.h: No such file or directory
port install oniguruma
gem install ultraviolet&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Slide show also handles syntax highlighting for your code and can import external files into the presentation.&lt;/p&gt;

&lt;code&gt;&lt;pre&gt;# Import a file
&amp;lt;%= include &amp;#39;help.txt&amp;#39; %&amp;gt;
# Highlight and import code
&amp;lt;% code &amp;#39;test.pl&amp;#39;, :lang =&amp;gt; &amp;#39;perl&amp;#39; %&amp;gt; 
# Highlight inline code
&amp;lt;% code :lang =&amp;gt; &amp;#39;perl&amp;#39; do %&amp;gt; 
 my $code = &amp;#39;is simple&amp;#39;;
&amp;lt;% end %&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;All in all, it seems like it fits the bill.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id='summary'&gt;Summary&lt;/h3&gt;

&lt;p&gt;I probably missed some very nice alternatives. I know there is spod5 on CPAN, but that seems very similar to Pod::S5. I&amp;#8217;m sure there are more. Let me know if I should be trying out your favorite.&lt;/p&gt;

&lt;p&gt;One other aspect that I&amp;#8217;ve been tinkering with: printing the presentation. I don&amp;#8217;t need it for the PM presentation I am working on, but if I were to try to switch from PowerPoint to Slide Share for my day job, I would definitely need a way to create &lt;code&gt;.pdf&lt;/code&gt; files.&lt;/p&gt;

&lt;p&gt;This seems like an issue that &lt;a href='http://groups.google.com/group/webslideshow/browse_thread/thread/49741671079ad402/c352d6e28ff0dd61?lnk=gst&amp;amp;q=print#c352d6e28ff0dd61'&gt;others&lt;/a&gt; are running into, but there is no great solution so far. It looks like the trick may be to customize the &lt;code&gt;print.css&lt;/code&gt; file. The following should change the page layout and add page breaks:&lt;/p&gt;

&lt;code&gt;&lt;pre class='brush: css'&gt;@page {size: landscape;}  /* only works in Opera? */
.slide {page-break-after: always;}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;But we are still missing the nice background and layout. I&amp;#8217;ll need to spend some more time on this.&lt;/p&gt;

&lt;p&gt;Last note: I stumbled into what may be a nice tool to convert a web page to &lt;code&gt;.pdf&lt;/code&gt; from the command line: &lt;a href='http://code.google.com/p/wkhtmltopdf/'&gt;wkhtmltopdf&lt;/a&gt;. It barfed on my S6 presentation, but it printed a few other websites nicely.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/533407576171979325-8637523731079330101?l=code-and-hacks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-and-hacks.blogspot.com/feeds/8637523731079330101/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://code-and-hacks.blogspot.com/2010/04/open-source-presentation-software.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/533407576171979325/posts/default/8637523731079330101'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/533407576171979325/posts/default/8637523731079330101'/><link rel='alternate' type='text/html' href='http://code-and-hacks.blogspot.com/2010/04/open-source-presentation-software.html' title='Open Source Presentation Software'/><author><name>Mark</name><uri>http://www.blogger.com/profile/09695682449145009572</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='27' src='http://1.bp.blogspot.com/_3S63aFOwxrA/SfdpX4ggnSI/AAAAAAAAAcc/hMmQj6rMYUU/S220/103008-full-oil.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-533407576171979325.post-4880038396025886799</id><published>2009-10-21T10:00:00.000-07:00</published><updated>2010-04-02T07:37:04.289-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='catalyst'/><category scheme='http://www.blogger.com/atom/ns#' term='perl'/><title type='text'>Making Catalyst Debug Logs Really Be Quiet</title><content type='html'>&lt;p&gt;I have recently been adding and updating tests to my biggest Catalyst project and have been a bit perplexed by the debugging output...in particular that I was seeing any of it! Generally, I like to see all that output scroll by, but when running &lt;code&gt;Test::WWW::Mechanize::Catalyst&lt;/code&gt; tests over and over again, it just clutters things and obfuscates any failures.&lt;/p&gt;

&lt;p&gt;I had removed &lt;code&gt;-Debug&lt;/code&gt; from the plugin list and tried &lt;code&gt;CATALYST_DEBUG=0&lt;/code&gt; env variable, but I continued to see a lot of the debug messages. After a bit of googling, I finally learned that this was a feature.&lt;/p&gt; 

&lt;p&gt;The &lt;code&gt;-Debug&lt;/code&gt; flag and &lt;code&gt;CATALYST_DEBUG&lt;/code&gt; env variable are just for the &lt;i&gt;internal&lt;/i&gt; Catalyst debug logs.  What I needed to do was to set the log levels with &lt;code&gt;MyApp-&amp;gt;log-&amp;gt;levels&lt;/code&gt; to control what is dumped with &lt;code&gt;$c-&amp;gt;log-&amp;gt;debug&lt;/code&gt; and its brethren. In general, I want my custom debugging and the internal Catalyst debugging to be tied together, so I added the following to &lt;code&gt;lib/MyApp.pm&lt;/code&gt; after &lt;code&gt;__PACKAGE__-&amp;gt;setup&lt;/code&gt;:&lt;/p&gt;

&lt;pre class="brush: perl"&gt;
__PACKAGE__-&amp;gt;log-&amp;gt;levels( qw/info warn error fatal/ ) unless __PACKAGE__-&amp;gt;debug;
&lt;/pre&gt;

&lt;p&gt;Now, if I run the server with &lt;code&gt;-d&lt;/code&gt; or do something like "&lt;code&gt;CATALYST_DEBUG=1 prove -l t&lt;/code&gt;" I see all the usual log message, otherwise I get nice clean test output.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/533407576171979325-4880038396025886799?l=code-and-hacks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-and-hacks.blogspot.com/feeds/4880038396025886799/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://code-and-hacks.blogspot.com/2009/05/making-catalyst-debug-logs-really-be.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/533407576171979325/posts/default/4880038396025886799'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/533407576171979325/posts/default/4880038396025886799'/><link rel='alternate' type='text/html' href='http://code-and-hacks.blogspot.com/2009/05/making-catalyst-debug-logs-really-be.html' title='Making Catalyst Debug Logs Really Be Quiet'/><author><name>Mark</name><uri>http://www.blogger.com/profile/09695682449145009572</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='27' src='http://1.bp.blogspot.com/_3S63aFOwxrA/SfdpX4ggnSI/AAAAAAAAAcc/hMmQj6rMYUU/S220/103008-full-oil.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-533407576171979325.post-56169880609312339</id><published>2009-10-14T10:00:00.000-07:00</published><updated>2010-04-02T07:38:10.699-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='blog admin'/><category scheme='http://www.blogger.com/atom/ns#' term='mac'/><category scheme='http://www.blogger.com/atom/ns#' term='perl'/><title type='text'>Moving to a Mac... which Perl?</title><content type='html'>&lt;p&gt;We'll after neglecting this blog for quite some time, I'm now back. I had to swap my laptop during the summer, and I decided to give one of the MacBook Pros a try. So I'll be adding Perl on the Mac and the Mac in general to the topics covered here.  My first dilemma with the new Mac was which perl to use.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Leopard only had 5.8 installed, and I've been hooked on 5.10 for a while now. (Snow Leopard has added 5.10, but by the time I got the upgrade I was commited to the ideal of keeping the system perl separate from my development perl.)&lt;/li&gt;
&lt;li&gt;Having come from Arch Linux, I stumbled upon and really liked Arch OS/X. Unfortunately, it appears that it isn't as well tested as MacPorts. In order to build any Perl modules that us XS with the Arch OS/X perl, I needed to use:

&lt;pre class="brush: bash"&gt;
$ perl Makefile.PL \
    LDDLFLAGS="-arch x86_64 -arch i386 -arch ppc \
             -bundle -undefined dynamic_lookup -L/usr/local/lib" \  
    LDFLAGS="-arch x86_64 -arch i386 -arch ppc -L/usr/local/lib" \
    CCFLAGS="-arch x86_64 -arch i386 -arch ppc -g -pipe \
             -fno-common -DPERL_DARWIN -fno-strict-aliasing \
             -I/usr/local/include -I." \
    OPTIMIZE="-Os"
&lt;/pre&gt;

Ummm... I don't think so! While I created an bash alias for it, cpan/cpanp where requiring constant tweaks. I assume I could have exported those variable from my bashrc, but I would rather avoid global changes like that.&lt;/li&gt;
&lt;li&gt;Next I tried compiling my own perl. I ended up doing it several times as I learned where to put it, and realized I had forgotten to enable things like threads. This really seems to be the best way to go, but I would rather someone else keep up with security patches, new versions, etc.&lt;/li&gt;
&lt;li&gt;So finally I tried MacPorts. So far so good. I have had trouble remembering to check the variants (&lt;code&gt;port variants &amp;lt;port-file&amp;gt;&lt;/code&gt;), but otherwise thumbs up.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One thing I realized that I want, is a record of all the ports that I have installed (not a list of all the &lt;i&gt;installed&lt;/i&gt; ports, just those that I had purposely installed). So, I wrote a short bash script that I stuck in &lt;code&gt;~/bin/port&lt;/code&gt; to keep a log:&lt;p&gt;
&lt;pre class="brush: bash"&gt;
#!/bin/bash

case "$1" in
  install|uninstall|upgrade|activate )
      echo "`date` $@" &amp;gt;&amp;gt; ~/.macports.log
      ;;
  *)      
esac

/opt/local/bin/port $@
&lt;/pre&gt;
&lt;p&gt;Now anytime I run &lt;code&gt;port install perl5.10 +shared +threads&lt;/code&gt; it is added to a log file. Rebuilding the system should be a snap. (I'm sure I could have gotten this by grepping for &lt;code&gt;sudo&lt;/code&gt; and &lt;code&gt;port install&lt;/code&gt; from the /var/log/system.log* files, but I like having it all in one place and not worrying about log files being rotated out.)&lt;/p&gt;

&lt;p&gt;One other tweak I need to make, was for &lt;code&gt;CPANPLUS&lt;/code&gt;. I wanted to be able to install modules in either the system perl (by running &lt;code&gt;/usr/bin/cpanp&lt;/code&gt;) or the MacPort perl (&lt;code&gt;/opt/local/bin/cpanp&lt;/code&gt;), but both of those read my user config file (&lt;code&gt;~/.cpanplus/lib/CPANPLUS/Config/User.pm&lt;/code&gt;) which need a full path for &lt;code&gt;perlwrapper =&amp;gt; '/usr/bin/cpanp-run-perl'&lt;/code&gt;. So I moved just that part of the config to the system config file by runnning the following in each cpanp:&lt;/p&gt;

&lt;pre class="brush: bash"&gt;
$ s save system
$ s edit system
&lt;/pre&gt;

&lt;p&gt;Then removing everything but the &lt;code&gt;perlwrapper&lt;/code&gt; configuration. And finally taking the &lt;code&gt;perlwrapper&lt;/code&gt; configuration out of my &lt;code&gt;User.pm&lt;/code&gt; file.  One other thing I needed to do to make 5.10 the default perl. MacPort defaults to perl5.8, but the following took care of that: &lt;/p&gt;

&lt;pre class="brush: bash"&gt;
$ cd /opt/local/bin
$ sudo mv perl perl.bak
$ sudo cp perl-5.10 perl
# make cpanp -&amp;gt; cpanp-5.10, etc.
$ for i in *-5.10 ; do x=${i%%-5.10} ;  sudo mv $x $x-5.8 ; sudo ln -s $i $x ; done 
&lt;/pre&gt;

&lt;p&gt;I see Python has a &lt;code&gt;python_select&lt;/code&gt; port-file. Maybe we need something like that for Perl.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/533407576171979325-56169880609312339?l=code-and-hacks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-and-hacks.blogspot.com/feeds/56169880609312339/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://code-and-hacks.blogspot.com/2009/10/moving-to-mac-which-perl.html#comment-form' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/533407576171979325/posts/default/56169880609312339'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/533407576171979325/posts/default/56169880609312339'/><link rel='alternate' type='text/html' href='http://code-and-hacks.blogspot.com/2009/10/moving-to-mac-which-perl.html' title='Moving to a Mac... which Perl?'/><author><name>Mark</name><uri>http://www.blogger.com/profile/09695682449145009572</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='27' src='http://1.bp.blogspot.com/_3S63aFOwxrA/SfdpX4ggnSI/AAAAAAAAAcc/hMmQj6rMYUU/S220/103008-full-oil.jpg'/></author><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-533407576171979325.post-447371387902459840</id><published>2009-07-04T13:50:00.001-07:00</published><updated>2010-04-02T07:39:11.611-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='vim'/><category scheme='http://www.blogger.com/atom/ns#' term='perl'/><title type='text'>Stealing from Padre for Vim part 3</title><content type='html'>&lt;p&gt;As promised in my &lt;a href="http://code-and-hacks.blogspot.com/2009/06/more-theft-from-padre.html"&gt;last&lt;/a&gt; post, I have released a new version of &lt;a href="http://search.cpan.org/perldoc?App::EditorTools"&gt;App::EditorTools&lt;/a&gt; and have a number of screenshots of the new functionality. This version includes &lt;code&gt;App::EditorTools::Vim&lt;/code&gt;, which provides an easy way to add the vim scripts to integrate the package into Vim.&lt;/p&gt;

&lt;pre class="brush: bash"&gt;
perl -MApp::EditorTools::Vim -e run &amp;gt; ~/.vim/ftplugin/perl/editortools.vim
&lt;/pre&gt;

&lt;p&gt;And now you should have the following mappings:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;,pp - Show a menu of the functions availabe from &lt;code&gt;App::EditorTools&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;,pL - Lexically rename the variable under the cursor (make sure the cursor is at the start of the variable for now&lt;/li&gt;
&lt;li&gt;,pP - Rename the package based on the path of the current buffer&lt;/li&gt;
&lt;li&gt;,pI - Introduce a temporary variable&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Here are a few screenshots of these actions:&lt;/p&gt;

&lt;p&gt;Lexically Rename Variables:&lt;br/&gt;
&lt;img src="http://peculier.com/blog/vim-renamevar.gif" alt="vim-renamevar" /&gt;&lt;br/&gt;

Rename Package based on the current file's path:&lt;br/&gt;
&lt;img src="http://peculier.com/blog/vim-renamepackage.gif" alt="vim-renamepackage" /&gt;&lt;br/&gt;

Introduce Temporary Variable&lt;br/&gt;
&lt;img src="http://peculier.com/blog/vim-introtempvar.gif" alt="vim-introtempvar" /&gt;&lt;br/&gt;
&lt;/p&gt;

&lt;p&gt;I'd love to hear feedback and any suggestions for future PPI based tools that Vim, Padre and other editors could leverage.&lt;/p&gt;

&lt;p&gt;I also have to note that the &lt;code&gt;editortools-vim&lt;/code&gt; script from &lt;code&gt;App::EditorTools&lt;/code&gt; was very easy to put together (although it still needs a fair amount of clean-up work and documentation) since is was based on Ricardo's &lt;a href="http://search.cpan.org/perldoc?App::Cmd"&gt;App::Cmd&lt;/a&gt;--very easy to use and feature rich.&lt;/p&gt;

&lt;p&gt;** Updated 7/5/09 10:37am: moved the screencasts to an external server and fixed some spelling&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/533407576171979325-447371387902459840?l=code-and-hacks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-and-hacks.blogspot.com/feeds/447371387902459840/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://code-and-hacks.blogspot.com/2009/07/stealing-from-padre-for-vim-part-3.html#comment-form' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/533407576171979325/posts/default/447371387902459840'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/533407576171979325/posts/default/447371387902459840'/><link rel='alternate' type='text/html' href='http://code-and-hacks.blogspot.com/2009/07/stealing-from-padre-for-vim-part-3.html' title='Stealing from Padre for Vim part 3'/><author><name>Mark</name><uri>http://www.blogger.com/profile/09695682449145009572</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='27' src='http://1.bp.blogspot.com/_3S63aFOwxrA/SfdpX4ggnSI/AAAAAAAAAcc/hMmQj6rMYUU/S220/103008-full-oil.jpg'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-533407576171979325.post-8917847753781731799</id><published>2009-06-27T22:54:00.000-07:00</published><updated>2009-10-13T11:08:33.057-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='vim'/><category scheme='http://www.blogger.com/atom/ns#' term='perl'/><title type='text'>More theft from Padre</title><content type='html'>&lt;p&gt;I was pleasantly surprise at the positive response to my last post on Stealing from Padre for Vim--particularly from the Padre developers! Seems they had hoped/planned on separating some of the tools out of the Padre core from the beginning (and many seem to be vimmers).&lt;/p&gt;

&lt;p&gt;With their blessing and encouragement, I have pulled the editor independent parts of their PPI::Task tools into its own distribution--&lt;a href="http://search.cpan.org/perldoc?PPIx::EditorTools"&gt;PPIx::EditorTools&lt;/a&gt;--available now on CPAN. I also adapted the current version of Padre to work wit the external package and released &lt;a href="http://search.cpan.org/perldoc?App::EditorTools"&gt;App::EditorTools&lt;/a&gt; to provide a command line interface for those editors that need it (i.e., vim). I'll post another screencast and the Vim scripts needed to integrate it shortly.&lt;/p&gt;

&lt;p&gt;As a result, I'm depreciating App::LexVarRepl--which was only ever available on github.&lt;/p&gt;

&lt;p&gt;Sorry for the short post which is light on links and code, but we are in the process of moving so I'm dedicating the few moments I have to coding this rather than blogging about it...for now at least!&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/533407576171979325-8917847753781731799?l=code-and-hacks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-and-hacks.blogspot.com/feeds/8917847753781731799/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://code-and-hacks.blogspot.com/2009/06/more-theft-from-padre.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/533407576171979325/posts/default/8917847753781731799'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/533407576171979325/posts/default/8917847753781731799'/><link rel='alternate' type='text/html' href='http://code-and-hacks.blogspot.com/2009/06/more-theft-from-padre.html' title='More theft from Padre'/><author><name>Mark</name><uri>http://www.blogger.com/profile/09695682449145009572</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='27' src='http://1.bp.blogspot.com/_3S63aFOwxrA/SfdpX4ggnSI/AAAAAAAAAcc/hMmQj6rMYUU/S220/103008-full-oil.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-533407576171979325.post-3503811690242313609</id><published>2009-06-16T22:00:00.000-07:00</published><updated>2009-10-13T10:31:28.810-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='vim'/><category scheme='http://www.blogger.com/atom/ns#' term='perl'/><title type='text'>Stealing from Padre for Vim</title><content type='html'>I'm sure the &lt;a href="http://search.cpan.org/perldoc?Padre"&gt;Padre&lt;/a&gt; developers weren't hoping to have their code absconded for those of us addicted to vim, but tsee's recent blog &lt;a href="http://use.perl.org/%7Etsee/journal/39121?from=rss"&gt;post&lt;/a&gt; on refactoring with Padre's lexical variable replace made me jealous--I want that for vim! So hack, hack, hack and &lt;i&gt;voila&lt;/i&gt;:&lt;br /&gt;
&lt;br /&gt;
&lt;img alt="screenshot" src="http://peculier.com/blog/lexvarrepl.gif" /&gt;  &lt;br /&gt;
This really is just leveraging the Padre code. At this point I actually &lt;code&gt;use Padre::PPI&lt;/code&gt; but that has the downside of requiring &lt;code&gt;Wx&lt;/code&gt; (which I personally like but it is quite a requirement). I only added a bit of code to make this into its own package and included some hints on vim scripting. The idea is to show how this could be abstracted into a standalone module then Padre, vim and any other reasonably powerful editor could use it. For now, I have packaged it as &lt;code&gt;App::LexVarReplace&lt;/code&gt; with &lt;code&gt;App::LexVarReplace::Vim&lt;/code&gt; pod. I would appreciate suggestions on the package layout and name, and any feedback from the Padre guys would be great.  The git repository is &lt;a href="http://github.com/mvgrimes/app-lexicalvarrepl/tree/master"&gt;available&lt;/a&gt; for your perusal.  I must say that Padre seems very cool. I continue to check it out every once in a while, but I just can't seem to give up vim, &lt;a href="http://www.gnu.org/software/screen/"&gt;gnu screen&lt;/a&gt; and a good old xterm. The developers have really done a great job leveraging modern Perl tools. You should check it out!  I am only publishing this on github for now. I would like to speak with tsee or one of the Padre developers before this makes it debut on CPAN, but I'm a bit short on time at the moment.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/533407576171979325-3503811690242313609?l=code-and-hacks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-and-hacks.blogspot.com/feeds/3503811690242313609/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://code-and-hacks.blogspot.com/2009/06/stealing-from-padre-for-vim.html#comment-form' title='16 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/533407576171979325/posts/default/3503811690242313609'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/533407576171979325/posts/default/3503811690242313609'/><link rel='alternate' type='text/html' href='http://code-and-hacks.blogspot.com/2009/06/stealing-from-padre-for-vim.html' title='Stealing from Padre for Vim'/><author><name>Mark</name><uri>http://www.blogger.com/profile/09695682449145009572</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='27' src='http://1.bp.blogspot.com/_3S63aFOwxrA/SfdpX4ggnSI/AAAAAAAAAcc/hMmQj6rMYUU/S220/103008-full-oil.jpg'/></author><thr:total>16</thr:total></entry><entry><id>tag:blogger.com,1999:blog-533407576171979325.post-2754283076301198555</id><published>2009-06-11T11:23:00.000-07:00</published><updated>2010-04-02T07:42:19.122-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='vim'/><category scheme='http://www.blogger.com/atom/ns#' term='bash'/><category scheme='http://www.blogger.com/atom/ns#' term='perl'/><category scheme='http://www.blogger.com/atom/ns#' term='web'/><title type='text'>Web testing</title><content type='html'>&lt;p&gt;I have been stuck doing a lot of front-end web work lately and haven't had a chance to do much perl coding (I am planning on releasing an Mason based renderer for &lt;code&gt;Email::MIME::Kit&lt;/code&gt; soon though). I'm very impressed with the power of CSS in modern browsers. The last time I looked at it, browser incompatibilities really made it difficult to use. It is much better still, I find most of the work to be trial and error, so I have a couple of tips that have saved me some time going back and forth...&lt;/p&gt;

&lt;h3&gt;Quick Browser Refresh&lt;/h3&gt;
&lt;p&gt;I do all of my coding in vim and have ton of mappings (maybe I'll share some in future). One I really like right now it &lt;code&gt;,u&lt;/code&gt; which saves the current file then runs my &lt;a href="http://www.peculier.com/blog/xrefresh.html"&gt;xrefresh&lt;/a&gt; perl script which finds my Firefox window and refreshes the current page. It is a simple script that is based on &lt;code&gt;X11::GUITest&lt;/code&gt;. It works particularly well when I am using two monitors and can have the browser on in one of them. Here is the mapping, along with the &lt;code&gt;,U&lt;/code&gt; mapping which saves all files:&lt;/p&gt;
&lt;pre&gt;
nmap &amp;lt;silent&amp;gt; ,u :w&amp;lt;cr&amp;gt;:! xrefresh 'Gran Paradiso'&amp;lt;cr&amp;gt;
nmap &amp;lt;silent&amp;gt; ,U :wa&amp;lt;cr&amp;gt;:! xrefresh 'Gran Paradiso'&amp;lt;cr&amp;gt;
&lt;/pre&gt;
&lt;p&gt;It would probably be easy to extend this script to do things like refresh multiple browsers, refresh without using the cache, etc.&lt;/p&gt;

&lt;h3&gt;IE Testing with VBox&lt;/h3&gt;
&lt;p&gt;Next up is some fun with IE. (Oh, the hours wasted on you. Damn you IE!) Microsoft has actually been very helpful and &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=21EABB90-958F-4B64-B5F1-73D0A413C8EF&amp;displaylang=en"&gt;provided&lt;/a&gt; disk images that you can use to test web pages in a virtual machine on different versions of their browser. They expire periodically and they are designed for Microsoft Virtual PC so it take a bit of work to set them up on linux using &lt;a href="http://www.virtualbox.org"&gt;VirtualBox&lt;/a&gt;, so I created a bash script (&lt;a href="http://www.peculier.com/blog/create-ie-vbox.html
"&gt;create-ie-vbox&lt;/a&gt;) to do the heavy lifting.&lt;/p&gt;

&lt;p&gt;Once you &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=21EABB90-958F-4B64-B5F1-73D0A413C8EF&amp;displaylang=en"&gt;download&lt;/a&gt; the images run &lt;code&gt;create-ie-vbox &amp;lt;path-to-image-.exe&amp;gt;&lt;/code&gt; and wait a while. The script uses perl and File::Spec to find the absolute path to the .exe file
&lt;pre class="brush: bash"&gt;
exe_file=`echo $exe_file | perl -MFile::Spec -e'print File::Spec-&gt;rel2abs(&amp;lt;&amp;gt;)'`
&lt;/pre&gt;
then the &lt;code&gt;unrar&lt;/code&gt; command (and perl) to find the .vhd file and unpack it
&lt;pre class="brush: bash"&gt;
vhd_file=`unrar l $exe_file | perl -ne'/(\w[\s\w-]*\.vhd)/ &amp;&amp; print $1'`
nice unrar e "$exe_file" "$vhd_file" &amp;gt;&amp;gt; $log 2&amp;gt;&amp;1 \
   || die "Couldn't extract $vhd_file from $exe_file"
&lt;/pre&gt;
Then the big trick is to convert the .vhd file to a .vdi file. While VBox can work with .vhd files, Microsoft uses the same UUID for all of these disk images which VBox doesn't like. There is a command in VBoxManage to change the UUID(&lt;code&gt;VBoxManage internalcommands setvdiuuid "$vhd"&lt;/code&gt;) but there is an acknowledged bug that prevents it from being useful here. Instead we have to use &lt;code&gt;qemu&lt;/code&gt; to convert it to a raw disk and then &lt;code&gt;VBoxManage&lt;/code&gt; to convert that to a .vdi:
&lt;pre class="brush: bash"&gt;
nice qemu-img convert -O raw -f vpc "$vhd" "$raw" || die "Error converting to raw"
nice VBoxManage convertdd "$raw" "$vdi" || die "Error converting to vdi"
&lt;/pre&gt; 
Finally there are a number of &lt;code&gt;VBoxManage&lt;/code&gt; commands to create and register the image and disk.&lt;/p&gt;

&lt;p&gt;Once this is done, there is a bit more work that needs to be done within the vm to deal with some bugs and annoyances. The script prints out the remaining steps. Much thanks to George Ornbo who pointed the way on his &lt;a href="http://shapeshed.com/journal/testing_with_ie6_ie7_and_ie8_on_virtualbox/"&gt;blog&lt;/a&gt;. Note that this script only works on the XP disks at this point; I haven't bothered to test the Vista versions yet.&lt;/p&gt;

&lt;p&gt;BTW, most of my bash scripts use the &lt;code&gt;die()&lt;/code&gt; function (stolen from perl) which is very simple but handy:
&lt;pre class="brush: bash"&gt;
function die() {
 echo $@
 exit 1
}
&lt;/pre&gt;
&lt;/p&gt;

&lt;h3&gt;Browser Resize&lt;/h3&gt;
&lt;p&gt;Lastly, I like to check my pages in browsers at various widths. Most importantly (or is that annoyingly) 800px. Rather than change my screen resolution, I use this simple bash script to resize Firefox to the desire width (defaulting to 800 if nothing is supplied on the command line):
&lt;pre class="brush: bash"&gt;
#!/bin/bash

SIZE=${1:-800}
echo Resize to $SIZE width
wmctrl -r "Firefox" -e 0,-1,-1,$SIZE,-1
&lt;/pre&gt;
Simple, but gets the job done quickly!&lt;/p&gt;

&lt;p&gt;Hope these are helpful.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/533407576171979325-2754283076301198555?l=code-and-hacks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-and-hacks.blogspot.com/feeds/2754283076301198555/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://code-and-hacks.blogspot.com/2009/06/web-testing.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/533407576171979325/posts/default/2754283076301198555'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/533407576171979325/posts/default/2754283076301198555'/><link rel='alternate' type='text/html' href='http://code-and-hacks.blogspot.com/2009/06/web-testing.html' title='Web testing'/><author><name>Mark</name><uri>http://www.blogger.com/profile/09695682449145009572</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='27' src='http://1.bp.blogspot.com/_3S63aFOwxrA/SfdpX4ggnSI/AAAAAAAAAcc/hMmQj6rMYUU/S220/103008-full-oil.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-533407576171979325.post-497094844689028095</id><published>2009-06-05T09:12:00.000-07:00</published><updated>2010-04-02T07:42:39.237-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='perl'/><category scheme='http://www.blogger.com/atom/ns#' term='module'/><title type='text'>Get Lazy, Use Data::Pageset::Render</title><content type='html'>&lt;p&gt;I have been using the very nice &lt;a href="http://search.cpan.org/perldoc?Data::Pageset"&gt;Data::Pageset&lt;/a&gt; module for a while now. It makes separating you data into multiple pages very simple, and for very large datasets it has the &lt;code&gt;slide&lt;/code&gt; mode which helps keep your pager small (rather than have links to 100 pages, you get links to the first and last page and the five pages around your current page).&lt;/p&gt;

&lt;p&gt;Eventually, I got tired of recreating the same html code for each new pager. I first put together a simple &lt;a href="http://search.cpan.org/perldoc?HTML::Mason"&gt;Mason&lt;/a&gt; component, but found myself copying it between projects and starting to write one for TT. Eventually, I wrote &lt;a href="http://search.cpan.org/perldoc?Data::Pageset::Render"&gt;Data::Pageset::Render&lt;/a&gt;. The module (which is on CPAN) subclasses Data::Pageset and adds the &lt;code&gt;html&lt;/code&gt; method, which returns the html code, complete with links, to create your pager.&lt;/p&gt;

&lt;p&gt;Just create your pager object as you would with Data::Pageset adding &lt;code&gt;link_format =&gt; '&amp;lt;a href="http://www.blogger.com/q?page=%p"&amp;gt;%a&amp;lt;/a&amp;gt;'&lt;/code&gt; to the constructor, the &lt;code&gt;html&lt;/code&gt; method then eliminates all that redundant paging html.
&lt;pre class="brush: perl"&gt;
 my $pager_html = $pager-&amp;gt;html();
 # $pager_html is html "&amp;lt;&amp;lt; 1 ... 3 4 5 6 7 ... 10 &amp;gt;&amp;gt;" with appropriate links

 # A bit more control over the appearence of the current page:
 my $pager_html = $pager-&amp;gt;html( '&amp;lt;a href="http://www.blogger.com/q?page=%p"&amp;gt;%a&amp;lt;/a&amp;gt;', '[%a]' );
 # $pager_html is html "&amp;lt;&amp;lt; 1 ... 3 4 [5] 6 7 ... 10 &amp;gt;&amp;gt;" with appropriate links
&lt;/pre&gt;
&lt;/p&gt;

&lt;p&gt;This works great within a larger framework like TT or Mason:
&lt;pre&gt;
 # In a TT template all the paging html is reduced to just:
 [% pager.html() %]

 # or in a Mason template:
 &lt;% $pager-&amp;gt;html() %&gt;
&lt;/pre&gt;
&lt;/p&gt;

&lt;p&gt;There aren't very many configuration options now. If there is interest I might make some of the controls customizable (ie, the &amp;gt;&amp;gt; to move forward). Any suggestions are more than welcome.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/533407576171979325-497094844689028095?l=code-and-hacks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-and-hacks.blogspot.com/feeds/497094844689028095/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://code-and-hacks.blogspot.com/2009/06/get-lazy-use-datapagesetrender.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/533407576171979325/posts/default/497094844689028095'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/533407576171979325/posts/default/497094844689028095'/><link rel='alternate' type='text/html' href='http://code-and-hacks.blogspot.com/2009/06/get-lazy-use-datapagesetrender.html' title='Get Lazy, Use Data::Pageset::Render'/><author><name>Mark</name><uri>http://www.blogger.com/profile/09695682449145009572</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='27' src='http://1.bp.blogspot.com/_3S63aFOwxrA/SfdpX4ggnSI/AAAAAAAAAcc/hMmQj6rMYUU/S220/103008-full-oil.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-533407576171979325.post-2339358540344202902</id><published>2009-05-27T10:00:00.000-07:00</published><updated>2009-10-13T11:11:54.617-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='blog admin'/><category scheme='http://www.blogger.com/atom/ns#' term='perl'/><category scheme='http://www.blogger.com/atom/ns#' term='cpanp'/><title type='text'>Easy Access to Your Minicpan Repository</title><content type='html'>&lt;p&gt;I am a big fan of CPANPLUS and minicpan. I like the plugin structure and power of CPANPLUS. ([Warning: shameless plug follows] I have written a simple &lt;a target="_blank" rel="nofollow" href="http://search.cpan.org/dist/CPANPLUS-Shell-Default-Plugins-Prereqs/"&gt;plugin&lt;/a&gt; that allows you to see/install the prereqs for an module with commands like &lt;code&gt;cpanp /prereqs show&lt;/code&gt; or &lt;code&gt;cpanp /prereqs install&lt;/code&gt;.) And minicpan is great for getting work done on an airplane or when I am away from the net.&lt;/p&gt;

&lt;p&gt;One thing I have struggle with in the past is getting cpanp to use either my local minicpan mirror or another mirror other than my default. Editing the config file is not that hard, but it is far to permanent for what I am trying to do. So I wrote two simple scripts (basically tweaked versions of /usr/bin/cpanp) that change the mirror to my local minicpan or a mirror passed on the command line: &lt;a target="_blank" rel="nofollow" href="http://peculier.com/blog/cpanp-local.html"&gt;cpanp-local&lt;/a&gt; and &lt;a target="_blank" rel="nofollow" href="http://peculier.com/blog/cpanp-mirror.html"&gt;cpanp-mirror&lt;/a&gt;. Both could be significantly improved, documented and they should probably be combined, but they get the job done.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/533407576171979325-2339358540344202902?l=code-and-hacks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-and-hacks.blogspot.com/feeds/2339358540344202902/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://code-and-hacks.blogspot.com/2009/05/easy-access-to-your-minicpan-repository.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/533407576171979325/posts/default/2339358540344202902'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/533407576171979325/posts/default/2339358540344202902'/><link rel='alternate' type='text/html' href='http://code-and-hacks.blogspot.com/2009/05/easy-access-to-your-minicpan-repository.html' title='Easy Access to Your Minicpan Repository'/><author><name>Mark</name><uri>http://www.blogger.com/profile/09695682449145009572</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='27' src='http://1.bp.blogspot.com/_3S63aFOwxrA/SfdpX4ggnSI/AAAAAAAAAcc/hMmQj6rMYUU/S220/103008-full-oil.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-533407576171979325.post-8298254926706124432</id><published>2009-05-20T10:00:00.000-07:00</published><updated>2010-04-02T07:43:03.710-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='vim'/><title type='text'>Recovering After Vim Terminates</title><content type='html'>&lt;p&gt;When vim is shutdowns abnormally it leaves a bunch of .swp files around.&lt;sup&gt;1&lt;/sup&gt; Given the way I program (very iterative and test focused) those backups are rarely more current than the saved file. A great time saver to help with recovery is the vim &lt;code&gt;DiffOrig&lt;/code&gt; command. After learning about it on &lt;a href="http://stackoverflow.com/questions/63104/smarter-vim-recovery"&gt;StackOverflow&lt;/a&gt;, I put together the following bash script to find any swap files under the current directory, open each in vim, run DiffOrig and prompt to delete after you close vim.&lt;/p&gt;

&lt;pre class="brush: bash"&gt;
#!/bin/bash

swap_files=`find . -name "*.swp"`

for s in $swap_files ; do
     orig_file=`echo $s | perl -pe 's!/\.([^/]*).swp$!/$1!' `
     echo "Editing $orig_file"
     sleep 1
     vim -r $orig_file -c "DiffOrig"
     echo -n "  Ok to delete swap file? [y/n] "
     read resp
     if [ "$resp" == "y" ] ; then
             echo "  Deleting $s"
             rm $s
     fi
done
&lt;/pre&gt;

&lt;p&gt;I was planning on converting this to a vim function, but for now the extra step of exiting vim and answering a prompt works fine. Also, my vim already loads &lt;code&gt;DiffOrig&lt;/code&gt;. ArchLinux includes it in &lt;code&gt;/etc/vimrc&lt;/code&gt;. If your vim doesn't, I believe the following command will do it:
&lt;pre&gt;
if !exists(":DiffOrig")
command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
               \ | wincmd p | diffthis
endif
&lt;/pre&gt;
&lt;/p&gt;

&lt;p&gt;BTW Iron Men, I realize this post isn't really Perl focused, but it is usually Perl files that I'm recovering!&lt;/p&gt;

&lt;p style="font-size:78%;"&gt;
Footnotes:&lt;br/&gt;
1. Which is almost never vim's fault. More likely an ssh connection was terminated or something along those lines.
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/533407576171979325-8298254926706124432?l=code-and-hacks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-and-hacks.blogspot.com/feeds/8298254926706124432/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://code-and-hacks.blogspot.com/2009/05/recovering-after-vim-terminates.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/533407576171979325/posts/default/8298254926706124432'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/533407576171979325/posts/default/8298254926706124432'/><link rel='alternate' type='text/html' href='http://code-and-hacks.blogspot.com/2009/05/recovering-after-vim-terminates.html' title='Recovering After Vim Terminates'/><author><name>Mark</name><uri>http://www.blogger.com/profile/09695682449145009572</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='27' src='http://1.bp.blogspot.com/_3S63aFOwxrA/SfdpX4ggnSI/AAAAAAAAAcc/hMmQj6rMYUU/S220/103008-full-oil.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-533407576171979325.post-3582988377601987813</id><published>2009-05-06T10:00:00.000-07:00</published><updated>2009-10-13T11:13:30.086-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='photo'/><category scheme='http://www.blogger.com/atom/ns#' term='perl'/><title type='text'>Facial Detection and Recongition in Perl</title><content type='html'>&lt;p&gt;I just recently came across the new facial detection features in Picasa, and I have to say I am very impressed. This is a very useful feature and well implemented; once again Google has set the bar. Unfortunately, it is only available in the web version, and I have way too many photos to upload. Further, there seem to be more privacy concerns with a web version of a tool like this.&lt;/p&gt;

&lt;p&gt;So, I was very excited when I saw a brief mention of presentation about &lt;a href="http://opencv.willowgarage.com/wiki/"&gt;OpenCV&lt;/a&gt; from a Ruhr.pm meeting (thanks to &lt;a href="http://babyl.dyndns.org/techblog/2009/04/ruhrpm-die-meister-des-psycho-lamas.html"&gt;Yanick's blog&lt;/a&gt;). Maybe this was the tool to implement facial detection/recognition in my photos locally.&lt;/p&gt;

&lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_3S63aFOwxrA/SgG5GGo7EMI/AAAAAAAAAds/PHTI-kAnEzo/s1600-h/mntbitpicsmedium20090110192339.jpg"&gt;&lt;img style="margin: 0pt 0pt 10px 10px; float: right; cursor: pointer; width: 190px; height: 143px;" src="http://3.bp.blogspot.com/_3S63aFOwxrA/SgG5GGo7EMI/AAAAAAAAAds/PHTI-kAnEzo/s320/mntbitpicsmedium20090110192339.jpg" alt="" id="BLOGGER_PHOTO_ID_5332746948295987394" border="0" /&gt;&lt;/a&gt;Without going into much detail, OpenCV is a library of routines for facial detection, recognition, and similar computer vision tasks. So far, I have only experimented with the facial detection part and read a bit about the facial recognition routines. There is a handy Perl binding (&lt;a href="http://search.cpan.org/%7Ejiro/Image-ObjectDetect-0.11/lib/Image/ObjectDetect.pm"&gt;Image::ObjectDetect&lt;/a&gt;) for the facial detection part. With it and reference to the &lt;a href="http://ruhr.pm.org/files/opencv/docshot"&gt;slides&lt;/a&gt; from Ruhr.pm, I was able hack together a very simple &lt;a href="http://www.peculier.com/blog/find_faces.pl.html"&gt;script&lt;/a&gt; to look for and highlight faces in my photo collection.&lt;/p&gt;


&lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_3S63aFOwxrA/SgG8M0pQaAI/AAAAAAAAAd8/aCM38A0bH9Y/s1600-h/mntbitpicsmedium20090111155056.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 183px; height: 122px;" src="http://3.bp.blogspot.com/_3S63aFOwxrA/SgG8M0pQaAI/AAAAAAAAAd8/aCM38A0bH9Y/s320/mntbitpicsmedium20090111155056.jpg" alt="" id="BLOGGER_PHOTO_ID_5332750362259515394" border="0" /&gt;&lt;/a&gt;While there were many false positives and some missed faces, OpenCV and the script show promise. Most of the missed faces were either very small or profiles, and there is another "cascade" (essentially a set of configuration presets to the detection algorithm) that might yield better results for profiles.&lt;/p&gt;

&lt;p&gt;Reading about facial recognition from the &lt;a href="http://opencv.willowgarage.com/wiki/FaceRecognition"&gt;OpenCV&lt;/a&gt; site was a bit underwhelming, though. Apparently OpenCV only supports one method of recognition, Principal Component Analysis. Which sounds like it has some sever limitations. From the site:&lt;/p&gt;

&lt;blockquote&gt;However it does have its weaknesses. PCA is &lt;em&gt;translation variant&lt;/em&gt; - Even if the images are shifted it wont recognize the face. It is &lt;em&gt;Scale variant&lt;/em&gt; - Even if the images are scaled it will be difficult to recognize. PCA is &lt;em&gt;background variant&lt;/em&gt;- If you want to recognize face in an image with different background, it will be difficult to recognize. Above all, it is &lt;em&gt;lighting variant&lt;/em&gt;- if the light intensity changes, the face wont be recognized that accurate. &lt;/blockquote&gt;

&lt;p&gt;Not exactly a great marketing pitch! PCA doesn't sounds like the most suitable method for recognizing faces from arbitrary photos. I haven't played with it yet, but that's on the todo list.&lt;/p&gt;

&lt;p&gt;To sum it all up, OpenCV looks like a great tool. I'll update this blog as I continue to experiment with it and my homebrew version of PicasaWeb's facial detection/recognition features. If anyone else has had experience with OpenCV or other facial detection/recognition tools (particularly those with Perl interfaces) I would love to hear about it.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/533407576171979325-3582988377601987813?l=code-and-hacks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-and-hacks.blogspot.com/feeds/3582988377601987813/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://code-and-hacks.blogspot.com/2009/05/facial-detection-and-recongition-in.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/533407576171979325/posts/default/3582988377601987813'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/533407576171979325/posts/default/3582988377601987813'/><link rel='alternate' type='text/html' href='http://code-and-hacks.blogspot.com/2009/05/facial-detection-and-recongition-in.html' title='Facial Detection and Recongition in Perl'/><author><name>Mark</name><uri>http://www.blogger.com/profile/09695682449145009572</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='27' src='http://1.bp.blogspot.com/_3S63aFOwxrA/SfdpX4ggnSI/AAAAAAAAAcc/hMmQj6rMYUU/S220/103008-full-oil.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_3S63aFOwxrA/SgG5GGo7EMI/AAAAAAAAAds/PHTI-kAnEzo/s72-c/mntbitpicsmedium20090110192339.jpg' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-533407576171979325.post-7662515099256641689</id><published>2009-04-29T08:37:00.001-07:00</published><updated>2010-04-02T07:40:10.247-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='blog admin'/><category scheme='http://www.blogger.com/atom/ns#' term='perl'/><title type='text'>C-Like Pointers In Perl...Oh No!</title><content type='html'>&lt;p&gt;Tuesday night David Lowe gave a very interesting &lt;a href="http://www.slideshare.net/j_david_lowe/how-to-hack-with-pack-and-unpack"&gt;talk&lt;/a&gt; at SF.pm on &lt;code&gt;pack/unpack&lt;/code&gt; and some of the awful things you can do with them.&lt;sup&gt;1&lt;/sup&gt; We ended the meeting talking about whether you could use the pack format "P" (which packs and unpacks "a pointer to a structure (fixed-length string)") to force poor Perl to do C-like pointer arithmetic.&lt;/p&gt;

&lt;p&gt;David is using &lt;code&gt;unpack&lt;/code&gt; to do a binary search of fixed width blobs of data in order to avoid unserializing it. His current (minor) bottleneck is creating the pack format string dynamically for each step in the binary search (ie, &lt;code&gt;'x' . ($record_size * $record + 1)&lt;/code&gt;). The math is fast, the string concatenation is relatively slow. I wondered if you could use the "P" format to avoid creating the format string on each pass and stick with simple integer arithmetic.&lt;/p&gt;

&lt;p&gt;After a bit of hacking, it turns out this can be done. Instead of David's very complicated:&lt;/p&gt;

&lt;pre class="brush: perl"&gt;
# Create an unpack format to skip the first $record * $record_size 
# bytes, then return the next 100 byte null padded string
my $format  = 'x' . ( $record_size * $record ) . 'Z100';
# Unpack from our binary blob
my $element = unpack( $format, ${$frozen_haystack_ref} );
&lt;/pre&gt;

&lt;p&gt;You get the nearly unfathomable:&lt;/p&gt;
 
&lt;pre class="brush: perl"&gt; 
# Use pointer arithmetic to calculate where the record is in memory
# and convert the Perl integer into an unsigned long integer
my $ptr     = pack( 'L!', $ptr_to_base + $record_size * $record );
# Pull 100 bytes from that spot in memory
my $element = unpack( 'P100', $ptr );
&lt;/pre&gt;

&lt;p&gt;And &lt;em&gt;voila&lt;/em&gt;, Perl is doing pointer arithmetic and accessing structures just like C. Unfortunately, &lt;code&gt;unpack("P")&lt;/code&gt; won't take a native Perl integer as an argument. You need to use &lt;code&gt;pack("L!")&lt;/code&gt; to turn a Perl integer it into a long integer. So we trade the string concatenation in David's code for a &lt;code&gt;pack("L!")&lt;/code&gt; in this code. And even worse, string concatenation is about 20% faster than &lt;code&gt;unpack&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So, while this doesn't appear to help David speed up his already cheetah like code, it does prove that you can have pointers in Perl. Of course, you should never ever do anything like this. It is fraught with potential bugs and will drive anyone stuck maintaining your code insane.&lt;/p&gt;

&lt;p&gt;Feel free to take apart my ugly &lt;a href="http://www.peculier.com/blog/pack-test.pl.html"&gt;benchmarking code&lt;/a&gt;. Maybe someone who knows this better can actually save David a few clock-cycles.&lt;/p&gt;

--

&lt;p&gt;By the way, thanks to &lt;a target="_blank" rel="nofollow" href="http://www.shadowcat.co.uk/blog/matt-s-trout/iron-man/"&gt;Matt Trout&lt;/a&gt; who got me motivated to (re)start blogging about Perl. In the past, I have gotten bogged down by setting up a site rather than focusing on adding content&lt;sup&gt;2&lt;/sup&gt;. This time I decided to let Google do the work for me and focus on the content. Hopefully, this will result in more regular (and interesting?) posts. Feedback is very welcome.&lt;/p&gt;

&lt;p&gt;Footnotes:&lt;br/&gt;
1. David actually has good reasons to do these horrible things, given some of the performance demands of his code, for the rest of us this is just fun^H^H^Hwrong.
2. Either putting together my own TT based &lt;a target="_blank" rel="nofollow" href="http://peculier.com/code"&gt;blog/site&lt;/a&gt; or trying to get MT to work the way I want.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/533407576171979325-7662515099256641689?l=code-and-hacks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-and-hacks.blogspot.com/feeds/7662515099256641689/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://code-and-hacks.blogspot.com/2009/04/c-like-pointers-in-perloh-no.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/533407576171979325/posts/default/7662515099256641689'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/533407576171979325/posts/default/7662515099256641689'/><link rel='alternate' type='text/html' href='http://code-and-hacks.blogspot.com/2009/04/c-like-pointers-in-perloh-no.html' title='C-Like Pointers In Perl...Oh No!'/><author><name>Mark</name><uri>http://www.blogger.com/profile/09695682449145009572</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='27' src='http://1.bp.blogspot.com/_3S63aFOwxrA/SfdpX4ggnSI/AAAAAAAAAcc/hMmQj6rMYUU/S220/103008-full-oil.jpg'/></author><thr:total>0</thr:total></entry></feed>
