<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Laufeyjarson writes... &#187; Perl</title>
	<atom:link href="http://blog.laufeyjarson.com/category/perl/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.laufeyjarson.com</link>
	<description>... notes, thoughts, rants, and randomness.</description>
	<lastBuildDate>Fri, 05 Apr 2013 05:29:17 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Template Toolkit Talk at SVPerl</title>
		<link>http://blog.laufeyjarson.com/2013/04/template-toolkit-talk-at-svperl/</link>
		<comments>http://blog.laufeyjarson.com/2013/04/template-toolkit-talk-at-svperl/#comments</comments>
		<pubDate>Fri, 05 Apr 2013 05:29:17 +0000</pubDate>
		<dc:creator>Laufeyjarson</dc:creator>
				<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://blog.laufeyjarson.com/?p=302</guid>
		<description><![CDATA[I gave a talk on Template Toolkit at the Sillicon Valley Perl meeting. I used these Template Toolkit Slides as I talked. Except I think I corrected the typos when I got home. =) It&#8217;s a fun group, and I always enjoy going, even when I&#8217;m the speaker.]]></description>
				<content:encoded><![CDATA[<p>I gave a talk on <a href="http://www.template-toolkit.org/">Template Toolkit</a> at the <a href="http://www.svperl.org">Sillicon Valley Perl</a> meeting. I used these <a href="http://blog.laufeyjarson.com/wp-content/uploads/2013/04/Template-Toolkit-Perl-Talk.pdf">Template Toolkit Slides</a> as I talked. Except I think I corrected the typos when I got home. =)</p>
<p>It&#8217;s a fun group, and I always enjoy going, even when I&#8217;m the speaker.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.laufeyjarson.com/2013/04/template-toolkit-talk-at-svperl/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Logitech Media Manager and Perl 5.16</title>
		<link>http://blog.laufeyjarson.com/2013/03/logitech-media-manager-and-perl-5-16/</link>
		<comments>http://blog.laufeyjarson.com/2013/03/logitech-media-manager-and-perl-5-16/#comments</comments>
		<pubDate>Sun, 17 Mar 2013 22:54:30 +0000</pubDate>
		<dc:creator>Laufeyjarson</dc:creator>
				<category><![CDATA[Audio]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[perl squeezebox suse linux]]></category>

		<guid isPermaLink="false">http://blog.laufeyjarson.com/?p=297</guid>
		<description><![CDATA[I have some Logitech Squeezeboxes.  Some of the older Slim Devices ones, too, actually, but they work together well. The nice people at Logitech have dropped the Squeezebox line to make a new cloud-based product.  Not my cup of tea. Problem: The Logitech Media Server software is old and balky, and installing it is a [...]]]></description>
				<content:encoded><![CDATA[<p>I have some Logitech Squeezeboxes.  Some of the older Slim Devices ones, too, actually, but they work together well.</p>
<p>The nice people at Logitech have dropped the Squeezebox line to make a new cloud-based product.  Not my cup of tea.</p>
<p>Problem: The Logitech Media Server software is old and balky, and installing it is a pain on new systems, because it includes binary versions of Perl modules.</p>
<p>Solution: Install perlbrew for the squeezebox user, install a supported Perl version there, and tweak the #! lines to use that squeezebox user&#8217;s perl install.</p>
<p>The right perl works fine, and since it&#8217;s in ~squeezebox, it won&#8217;t get screwed up when SuSE upgrades.</p>
<p>WAY easier than trying to fix the idiosyncratic Logitech Media Server software!</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.laufeyjarson.com/2013/03/logitech-media-manager-and-perl-5-16/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why I Dislike Autodie</title>
		<link>http://blog.laufeyjarson.com/2012/10/why-i-dislike-autodie/</link>
		<comments>http://blog.laufeyjarson.com/2012/10/why-i-dislike-autodie/#comments</comments>
		<pubDate>Tue, 23 Oct 2012 21:07:12 +0000</pubDate>
		<dc:creator>Laufeyjarson</dc:creator>
				<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://blog.laufeyjarson.com/?p=273</guid>
		<description><![CDATA[Many people have suggested I use autodie. I have never been interested in the functionality it provides, and don&#8217;t use it. I think there&#8217;s primarily two reasons why that is. I might know a way to address one of them, but it&#8217;s tricky. It&#8217;s Invisible The first reason is that I feel it changes the [...]]]></description>
				<content:encoded><![CDATA[<p>Many people have suggested I use autodie. I have never been interested in the functionality it provides, and don&#8217;t use it. I think there&#8217;s primarily two reasons why that is. I might know a way to address one of them, but it&#8217;s tricky.<span id="more-273"></span></p>
<h1>It&#8217;s Invisible</h1>
<p>The first reason is that I feel it changes the language a lot, and in ways that make it really hard for a new reader to follow. If you&#8217;re reading code that has no error checking in it, as a new or even mid-level Perl author, you&#8217;ll perhaps not realize that&#8217;s bad, or that it does have error checking. That checking being hidden in &#8220;use autodie&#8221; can be somewhat difficult to see.</p>
<p>As part of that difficulty, using autodie makes changes to all the Perl builtins.  When I need to use one, I look it up in perldoc.  perldoc tells me it returns false or undef or whatever in case of an error.  Except&#8230; that&#8217;s not true with autodie.  While I&#8217;m a good enough programmer to remember this about my own programs, it makes it a lot harder to tell what a particular piece of Perl code will do.</p>
<p>I&#8217;m really unhappy with the changes to the second edition of the Modern Perl book, because it&#8217;s assuming autodie everywhere.  I don&#8217;t want to give it to new Perl programmers any more because they&#8217;ll be confused, and the differences are subtle and almost entirely undocumented.  I can&#8217;t recommend the new version of this otherwise useful book to anyone who isn&#8217;t an expert Perl programmer and that&#8217;s a shame.</p>
<p>I don&#8217;t like making large-scale, undocumented changes to the language libraries any more.  At what point is it no longer Perl, but something new and different?</p>
<p>As an aside, I think a lot of expert Perl programmers forget that many people using Perl don&#8217;t know it has exceptions at all.  I often find people who are shocked to discover it does.  Some of them have even been using die for errors, and didn&#8217;t know how the whole thing works together.  Professional programmers, not script kiddies.  Happens all the time.</p>
<p>This concern of mine with autodie is actually a solvable problem.  The Perl core needs to incorporate autodie, and update al the perldocs to explain it.  If the perldoc for &#8220;unlink&#8221; said, &#8220;returns the number of files deleted. With autodie enabled, will die on error deleting files.&#8221; it would mean that a new author would have a chance to see what&#8217;s happening.  I don&#8217;t expect this to happen, but until it does, I consider autodie too sweeping a set of changes for a module to be making.</p>
<p>I probably wouldn&#8217;t use it anyway, because of this second reason:</p>
<h1>I Don&#8217;t Like Exceptions</h1>
<p>I&#8217;ve worked in a ton of languages that use exceptions.  I understand them, and I can use them.  I don&#8217;t like them.  I find it hard to write robust, resilient code with them.  Many people like them because you can put off or ignore error handling and capture it all in one place.  Your code is free of that distracting noise of error handling.</p>
<p>However, this means your code notices the errors in the wrong place to do anything about them, and has to pretty much fall over dead and crash.  It can&#8217;t try and fix things very well.  Or you can handle the exceptions very close to the place they might occur, littering your code with even more distracting and hard to read exception handling stanzas.</p>
<p>The most reliable and robust code I&#8217;ve ever written was about 70% error handling code.  In many cases it could recover from errors or try an alternative to keep running.  I find this much harder to do with exceptions, and exceptions in general much more difficult to manage.</p>
<p>If programmers were clamoring for a giant &#8220;ON ERROR GOTO&#8221; statement, while telling me that gotos were evil, I&#8217;d be really confused.  Yet, that&#8217;s what exceptions are.  Exceptions that many programmers never handle, and simply want the program to crash the first time something goes wrong.  I don&#8217;t want my program to crash every time something goes wrong; I want it to log the error and keep going, or ask again or try an alternative.</p>
<p>If &#8220;Go To Considered Harmful&#8221; is still valid &#8211; and it seems to me to be &#8211; why is ON ERROR GOTO allowed?  Isn&#8217;t that all an exception is?</p>
<p>I don&#8217;t know a way to change this preference of mine, and how to convince myself that it&#8217;s okay to just let things crash or to write horribly tangled code to pander to the needs of the exception handlers.  So, I don&#8217;t.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.laufeyjarson.com/2012/10/why-i-dislike-autodie/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Remember to store errors!</title>
		<link>http://blog.laufeyjarson.com/2012/08/remember-to-store-errors/</link>
		<comments>http://blog.laufeyjarson.com/2012/08/remember-to-store-errors/#comments</comments>
		<pubDate>Tue, 21 Aug 2012 00:04:37 +0000</pubDate>
		<dc:creator>Laufeyjarson</dc:creator>
				<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://blog.laufeyjarson.com/?p=247</guid>
		<description><![CDATA[In Perl, when you get an error, there are magic globals that the interpreter sets to the value of that error. If you&#8217;re going to do any other work before reporting the error, save those variables!  Work almost got this right&#8230; Here&#8217;s pseudo code of what I found at work today: $ok = link("$src/$file", "$dst/$file"); [...]]]></description>
				<content:encoded><![CDATA[<p>In Perl, when you get an error, there are magic globals that the interpreter sets to the value of that error. If you&#8217;re going to do any other work before reporting the error, save those variables!  Work almost got this right&#8230;<span id="more-247"></span></p>
<p>Here&#8217;s pseudo code of what I found at work today:</p>
<pre>$ok = link("$src/$file", "$dst/$file");</pre>
<pre>unless($ok) {</pre>
<pre>    my $log = $!;</pre>
<pre>    log_error_in_database($log);</pre>
<pre>    send_error_in_email($!);</pre>
<pre>}</pre>
<p>See the error?  The coder saved the error from $! in $log, and then passed it to the DB to store it.  The DB (which no one knew existed) had all the right errors.  Writing to the DB changed $! to a harmless non-error.  It wound up being &#8220;Resource temporarily unavailable&#8221; or whatever numeric value that is.  It&#8217;s meaningless, though, because it was set by calling some other stuff in the DB handling function.</p>
<p>Then, the code tries to e-mail it.  Clearly the DB was added later, as it didn&#8217;t use the copy they saved there, and used $!, sending the useless value to us in e-mail where we all looked at it.</p>
<p>(Edit: A sharp commenter suggested I actually show the fix, which is an excellent idea!)  Instead of storing your error, then forgetting to use it, use the stored error message in both places:</p>
<pre>$ok = link("$src/$file", "$dst/$file");</pre>
<pre>unless($ok) {</pre>
<pre>    my $log = $!;</pre>
<pre>    log_error_in_database($log);</pre>
<pre>    send_error_in_email(<strong>$log</strong>);</pre>
<pre>}</pre>
<p>Another alternative would be to use local on $!, but that&#8217;s not as sound, because every function you call also has to do the same, and it is hard to tell what module or library you use might get it wrong.  Saving a copy of $! for your code to use later will be safer.</p>
<p>The good news is that I eventually found, and realized the values were in the DB and looked there so I know what was going on and can try and make progress.</p>
<p>This is actually cleaner and simpler than the real code.  The real code actually did check the results of link(), which is good!  It doesn&#8217;t check mkdir() or chdir() anywhere, though&#8230;  It&#8217;s not the worst Perl I&#8217;ve ever seen, but it&#8217;s on the list of contenders.</p>
<p>I really, really want to replace this code with something that is less painful.  I have a nice, new Modern Perl version well underway.  We&#8217;ll see if management lets me finish and deploy it!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.laufeyjarson.com/2012/08/remember-to-store-errors/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Anti-documentation in Perldoc</title>
		<link>http://blog.laufeyjarson.com/2012/07/anti-documentation-in-perldoc/</link>
		<comments>http://blog.laufeyjarson.com/2012/07/anti-documentation-in-perldoc/#comments</comments>
		<pubDate>Sat, 28 Jul 2012 16:15:45 +0000</pubDate>
		<dc:creator>Laufeyjarson</dc:creator>
				<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://blog.laufeyjarson.com/?p=241</guid>
		<description><![CDATA[Found a section that annoyed me in perlsyn today, in the documentation for the foreach loop: Here&#8217;s how a C programmer might code up a particular algorithm in Perl: for (my $i = 0; $i &#60; @ary1; $i++) { for (my $j = 0; $j &#60; @ary2; $j++) { if ($ary1[$i] &#62; $ary2[$j]) { last; [...]]]></description>
				<content:encoded><![CDATA[<p>Found a section that annoyed me in perlsyn today, in the documentation for the foreach loop:<span id="more-241"></span></p>
<p style="padding-left: 30px;">Here&#8217;s how a C programmer might code up a particular algorithm in Perl:</p>
<pre style="padding-left: 30px;">for (<a href="http://perldoc.perl.org/functions/my.html">my</a> $i = 0; $i &lt; @ary1; $i++) {
    for (<a href="http://perldoc.perl.org/functions/my.html">my</a> $j = 0; $j &lt; @ary2; $j++) {
        if ($ary1[$i] &gt; $ary2[$j]) {
            <a href="http://perldoc.perl.org/functions/last.html">last</a>; # can't go to outer :-(
        }
    $ary1[$i] += $ary2[$j];
    }
    # this is where that last takes me
}</pre>
<p style="padding-left: 30px;">Whereas here&#8217;s how a Perl programmer more comfortable with the idiom might do it:</p>
<pre style="padding-left: 30px;">OUTER: for <a href="http://perldoc.perl.org/functions/my.html">my</a> $wid (@ary1) {
INNER:     for <a href="http://perldoc.perl.org/functions/my.html">my</a> $jet (@ary2) {
               <a href="http://perldoc.perl.org/functions/next.html">next</a> OUTER if $wid &gt; $jet;
               $wid += $jet;
           }
        }</pre>
<p style="padding-left: 30px;">See how much easier this is? It&#8217;s cleaner, safer, and faster. It&#8217;s cleaner because it&#8217;s less noisy. It&#8217;s safer because if code gets added between the inner and outer loops later on, the new code won&#8217;t be accidentally executed. The <code><a href="http://perldoc.perl.org/functions/next.html">next</a></code> explicitly iterates the other loop rather than merely terminating the inner one. And it&#8217;s faster because Perl executes a <code>foreach</code> statement more rapidly than it would the equivalent<code>for</code> loop.</p>
<p>First, the smug, &#8220;See how much easier this is?&#8221; makes me want to slap someone.  No, I don&#8217;t.  I see equally bad code.  One has a goto in the middle, and one uses awkward loops.  Both have no documentation, no explanation of what they&#8217;re doing, and indecipherable yet different variable names.  I have little to no confidence these snippets do the same thing because I can not tell what either of are supposed to do.</p>
<p>The concerns about why the code is bad seem to be vague as well.  &#8221;Cleaner because it&#8217;s less noisy.&#8221;  Really?  What does &#8220;noisy&#8221; mean?  I find the labels to be a fairly unusual construct that increase my cognitive load on reading the code pretty significantly.  Is that noisy?  I can almost see the argument for &#8216;safer&#8217;, but &#8216;safer&#8217; code that&#8217;s unreadable isn&#8217;t a good trade-off in my mind.</p>
<p>If I&#8217;ve learned anything about Perl, I&#8217;ve learned that comments about speed are often wrong.  I think this is actually correct, but I don&#8217;t think it matters.  This isn&#8217;t an advantage of for or foreach, but is a comment about choosing a better algorithm.  That really shouldn&#8217;t be a surprise, nor should it be part of the discussion of the for loop!</p>
<p>Worst, this makes me feel stupid.  I don&#8217;t see how this is &#8220;easier&#8221;, and I can&#8217;t read it at all and the text, by assuming I will and that this is crystal clear to every reader, seems to say to me, &#8220;You aren&#8217;t smart enough to write Perl.  Go away.&#8221;</p>
<p>This section of perldoc has been unhelpful since Perl 5.8.8 &#8211; over six years &#8211; and damaging people&#8217;s opinion of Perl that entire time.  Why do we keep writing things like this?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.laufeyjarson.com/2012/07/anti-documentation-in-perldoc/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Teaching Perl&#8230;</title>
		<link>http://blog.laufeyjarson.com/2012/07/teaching-perl/</link>
		<comments>http://blog.laufeyjarson.com/2012/07/teaching-perl/#comments</comments>
		<pubDate>Wed, 25 Jul 2012 22:02:49 +0000</pubDate>
		<dc:creator>Laufeyjarson</dc:creator>
				<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://blog.laufeyjarson.com/?p=233</guid>
		<description><![CDATA[I&#8217;ll be teaching a very informal class on Perl to  a couple of folks I know.  We&#8217;ve got two days scheduled, and I&#8217;ve suggested they get chromatic&#8217;s Modern Perl as a &#8216;textbook&#8217;.  I plan on covering what variables are, how program flow works, functions, and objects via Moose.  I&#8217;ll also discuss installing Perl on Windows [...]]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ll be teaching a very informal class on Perl to  a couple of folks I know.  We&#8217;ve got two days scheduled, and I&#8217;ve suggested they get chromatic&#8217;s Modern Perl as a &#8216;textbook&#8217;.  I plan on covering what variables are, how program flow works, functions, and objects via Moose.  I&#8217;ll also discuss installing Perl on Windows and Linux.  What am I forgetting?<span id="more-233"></span></p>
<p>Would people be interested in screencasts or videos?</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.laufeyjarson.com/2012/07/teaching-perl/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Perforce auth-check trigger for Unix passwd file</title>
		<link>http://blog.laufeyjarson.com/2012/02/perforce-auth-check-trigger-for-unix-passwd-file/</link>
		<comments>http://blog.laufeyjarson.com/2012/02/perforce-auth-check-trigger-for-unix-passwd-file/#comments</comments>
		<pubDate>Sat, 04 Feb 2012 04:56:04 +0000</pubDate>
		<dc:creator>Laufeyjarson</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[perl perforce]]></category>

		<guid isPermaLink="false">http://blog.laufeyjarson.com/?p=152</guid>
		<description><![CDATA[I just installed Perforce (what a hassle!) and discovered that it won&#8217;t authenticate to the local Unix accounts out of the box.  The nice folks at Perforce let you call an external trigger, and provide a complex sample that will handle talking to Active Directory, but don&#8217;t have one do handle ordinary Unix passwd access. [...]]]></description>
				<content:encoded><![CDATA[<p>I just installed Perforce (what a hassle!) and discovered that it won&#8217;t authenticate to the local Unix accounts out of the box.  The nice folks at Perforce let you call an external trigger, and provide a complex sample that will handle talking to Active Directory, but don&#8217;t have one do handle ordinary Unix passwd access.<span id="more-152"></span></p>
<p>Totally annoying.  A simple Perl script fixed it.  Don&#8217;t know why they didn&#8217;t put it in their samples, though.</p>
<pre>#!/usr/bin/perl

use strict;
use warnings;

=head1 NAME p4_check_passwd

Called with the user name on the command line and the password on standard
input, this program returns a success or failure depending on that password's
correctness.

Uses getpwnam to do so, and must run as root on in shadow group to access
/etc/shadow and password data.

This should be configured in p4 triggers as an auth-check trigger:

Triggers:
unixpw auth-check auth "/home/perforce/bin/p4_check_passwd.pl %user%"

This uses the crypt system call, which should handle any variants of encryption
in your password file. It also uses the getpwnam() function to access
the password data, so should be able to access data from NIS or other
configured password system.

=cut

# Perforce wants all messages on stdout. Guarantee that.
open(STDERR, "&gt;&amp;STDOUT") or die "Can't redirect to stdout\n";

# Get the user name
my $username = shift;
die "Need user name on command line\n" unless $username;

# Get the password
my $password = &lt;STDIN&gt;;
chomp $password;

# Get username and password from the system
my ($name, $passwd) = getpwnam($username);

die "Can't log in as $username\n" unless ($name and $username eq $name);
die "Can't access encrypted passwords\n" if(not defined $passwd or $passwd eq ''
or $passwd eq 'x');

# Check password and return correct exit code or die.
if(crypt($password, $passwd) eq $passwd) {
	exit 0; # Silent, successful exit worked!
} else {
	die "Can't log in as $username\n";
}</pre>
<p>Works for me, anyway.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.laufeyjarson.com/2012/02/perforce-auth-check-trigger-for-unix-passwd-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Can&#8217;t really override open()?</title>
		<link>http://blog.laufeyjarson.com/2010/12/cant-really-override-open/</link>
		<comments>http://blog.laufeyjarson.com/2010/12/cant-really-override-open/#comments</comments>
		<pubDate>Sun, 12 Dec 2010 05:18:35 +0000</pubDate>
		<dc:creator>Laufeyjarson</dc:creator>
				<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://blog.laufeyjarson.com/?p=127</guid>
		<description><![CDATA[A question came up at work the other day, if you could override the Perl open() function.  There&#8217;s many possible uses for this, but work&#8217;s was simple: we wanted a log of all files accessed during a program run.  The program is large, complex, and uses many modules.  An override of open() would let us [...]]]></description>
				<content:encoded><![CDATA[<p>A question came up at work the other day, if you could override the Perl open() function.  There&#8217;s many possible uses for this, but work&#8217;s was simple: we wanted a log of all files accessed during a program run.  The program is large, complex, and uses many modules.  An override of open() would let us record the file and open mode, then call CORE::open.</p>
<p>We couldn&#8217;t do it.  After a second look, I still can&#8217;t do it.  Not for all cases, anyway.<span id="more-127"></span></p>
<p>perlsub says lists a prototype of (*;$) for open, and discusses being careful not to override open by accident.  It also suggests prototype can show the prototypes for overridable items.</p>
<p>prototype &#8216;CORE::open&#8217; returns &#8220;*;$@&#8221;, which is interesting, but not a match for perlsub.  &#8221;*;$@&#8221; lets the function get called, though, and matches all the things open has to do.</p>
<p>I wrote a really simple wrapper for open:</p>
<pre> use Data::Dumper;</pre>
<pre>sub open(*;$@) {</pre>
<pre>    say Dumper(\@_);</pre>
<pre>}</pre>
<p>I wrote a function to call it a couple of ways:</p>
<pre>say "test 1:";</pre>
<pre>open (FH, '&gt;file.txt') or die "Can't &gt;file.txt: $!";</pre>
<pre>close FH;</pre>
<pre>say "test 2:";</pre>
<pre>open (FH, '&gt;', 'file.txt') or die "Can't &gt; file.txt: $!";</pre>
<pre>close FH;</pre>
<pre>say "test 3:";</pre>
<pre>open (my $fh, '&gt;', 'file.txt') or die "Can't my &gt; file.txt: $!";</pre>
<pre>close $fh;</pre>
<p>Now I can see what those look like:</p>
<pre>test 1:</pre>
<pre>$VAR1 = [</pre>
<pre>     'FH',</pre>
<pre>     '&gt;file.txt'</pre>
<pre> ];</pre>
<pre>test 2:</pre>
<pre>$VAR1 = [</pre>
<pre>     'FH',</pre>
<pre>     '&gt;',</pre>
<pre>     'file.txt'</pre>
<pre> ];</pre>
<pre>test 3:</pre>
<pre>$VAR1 = [</pre>
<pre>     undef,</pre>
<pre>     '&gt;',</pre>
<pre>     'file.txt'</pre>
<pre> ];</pre>
<p>Okay.  The two calls with typeglobs get the name of the glob.  I can work with that.</p>
<p>The call with a lexical, though, gets the value.  Where/how do I return the handle?</p>
<p>I messed around some more, and when using lexicals, a Perl open() function is called with the value of the lexical, not with any way to identify the variable itself.  I can&#8217;t figure out how to get the variable to pass to CORE::open, or to return something into it.</p>
<p>And there I&#8217;m stumped.  Is it possible that the docs in perlsub are from the 5.5 days and don&#8217;t work since Perl 5.6 introduced lexicals as file handles?  Or am I missing something?</p>
<p>I could go dig in to CPAN and see if any other modules do this right.  How does Safe.pm do it?  Can it be done in an XS module but not in Perl?</p>
<p>Back to useful work instead of banging my head against this.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.laufeyjarson.com/2010/12/cant-really-override-open/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Cool Tools To Know</title>
		<link>http://blog.laufeyjarson.com/2010/12/cool-tools-to-know/</link>
		<comments>http://blog.laufeyjarson.com/2010/12/cool-tools-to-know/#comments</comments>
		<pubDate>Sun, 05 Dec 2010 01:28:27 +0000</pubDate>
		<dc:creator>Laufeyjarson</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[cpan]]></category>

		<guid isPermaLink="false">http://blog.laufeyjarson.com/?p=116</guid>
		<description><![CDATA[chromatic mentioned something in the preface to his book Modern Perl that I had been looking for but hadn&#8217;t yet found.  He then went on to mention a couple of other things which were just plain neat.  I knew about one of them, but not the second and thought they were both great ideas and [...]]]></description>
				<content:encoded><![CDATA[<p>chromatic mentioned something in the preface to his book <a title="Modern Perl - book and download" href="http://www.onyxneon.com/books/modern_perl/index.html" target="_blank">Modern Perl</a> that I had been looking for but hadn&#8217;t yet found.  He then went on to mention a couple of other things which were just plain neat.  I knew about one of them, but not the second and thought they were both great ideas and thought I&#8217;d try and get them wider attention.<span id="more-116"></span></p>
<p>I&#8217;d been looking for a way to manage having multiple Perl installations on my system.  Ruby has something called the <a title="rvm - Ruby Version Manger" href="http://rvm.beginrescueend.com/" target="_blank">Ruby Version Manager</a> which makes this really straightforward, and I figured there had to be something like it for Perl.  I hadn&#8217;t looked much, but what I had didn&#8217;t get me anywhere.  The Preface for Modern Perl mentioned it in passing.  The tool is called <a title="App::perlbrew" href="http://search.cpan.org/perldoc?App%3A%3Aperlbrew" target="_blank">App::perlbrew</a> and allows you to easily switch from one Perl to another and can help manage those Perl installations.</p>
<p>Combine that with <a title="local::lib" href="http://search.cpan.org/perldoc?local%3A%3Alib" target="_blank">local::lib</a> so you can have your own installed modules, and you&#8217;ve almost got rvm.  The ability to have named module sets and turn them on and off at will is missing.  If it&#8217;s important, the two could be combined into a complete Perl environment management tool&#8230; but I don&#8217;t know if it is important.  A per-project Perl with modules installed might be enough.</p>
<p>One useful tool mentioned in Modern Perl is the Perl module <a title="Modern::Perl" href="http://search.cpan.org/perldoc?Modern%3A%3APerl" target="_blank">Modern::Perl</a>, also by chromatic.  It&#8217;s a helper to take some of the boilerplate that a modern Perl program should put in every program and module and condense it to one easy to read, clearer line of code.  It isn&#8217;t a big deal, but is nice.  (CPAN, as usual was full of similar things, but I didn&#8217;t think they were as well thought.)  I had heard of Modern::Perl because I&#8217;d been following chromatic&#8217;s blog.</p>
<p>The module I thought was really neat but hadn&#8217;t heard of was <a title="Task::Kensho" href="http://search.cpan.org/perldoc?Task%3A%3AKensho" target="_blank">Task::Kensho</a>.  This is part of the work of a group of folks who are trying to build an &#8220;Enlightened Perl&#8221; and is mostly references to other modules.  The module list includes some big stuff I&#8217;d run into &#8211; Moose, DBIx::Class &#8211; but also included a lot of just generally useful stuff that I&#8217;m sure will be handy.  There was also some things that were not critical but neat, like <a title="Smart::Comments" href="http://search.cpan.org/perldoc?Smart%3A%3AComments" target="_blank">Smart::Comments</a>.  There&#8217;s a bunch of stuff on that list I&#8217;ve been Meaning To Look At but haven&#8217;t gotten around to yet, like <a title="Devel::REPL" href="http://search.cpan.org/perldoc?Devel%3A%3AREPL" target="_blank">Devel::REPL</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.laufeyjarson.com/2010/12/cool-tools-to-know/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Linking to CPAN</title>
		<link>http://blog.laufeyjarson.com/2010/11/linking-to-cpan/</link>
		<comments>http://blog.laufeyjarson.com/2010/11/linking-to-cpan/#comments</comments>
		<pubDate>Sat, 27 Nov 2010 18:12:43 +0000</pubDate>
		<dc:creator>Laufeyjarson</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[perl CPAN]]></category>

		<guid isPermaLink="false">http://blog.laufeyjarson.com/?p=118</guid>
		<description><![CDATA[All through these blog pages, I&#8217;ve been linking to CPAN modules I&#8217;m talking about so that it&#8217;s easy for readers to find them.  I knew I was linking to specific versions, but couldn&#8217;t figure out how to link to the latest version of the module.  I noticed the docs for Task::Kensho do it, and am [...]]]></description>
				<content:encoded><![CDATA[<p>All through these blog pages, I&#8217;ve been linking to CPAN modules I&#8217;m talking about so that it&#8217;s easy for readers to find them.  I knew I was linking to specific versions, but couldn&#8217;t figure out how to link to the latest version of the module.  I noticed the docs for <a title="Task::Kensho" href="http://search.cpan.org/perldoc?Task%3A%3AKensho" target="_blank">Task::Kensho</a> do it, and am going to start doing it too.</p>
<p>The secret is to use links like this:  http://search.cpan.org/perldoc?Task%3A%3AKensho</p>
<p>The %3A are the URI encoding of a : so this goes to http://search.cpan.org/perldoc and searches for the module name automatically.  Neat.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.laufeyjarson.com/2010/11/linking-to-cpan/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
