<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>transfixed but not dead!</title>
	<atom:link href="http://transfixedbutnotdead.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://transfixedbutnotdead.com</link>
	<description>my ramblings on life, work &#38; anything left in-between</description>
	<lastBuildDate>Fri, 16 Jul 2010 19:57:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='transfixedbutnotdead.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/0a317653027efb1ab2bf8adde3dcb067?s=96&#038;d=http://s2.wp.com/i/buttonw-com.png</url>
		<title>transfixed but not dead!</title>
		<link>http://transfixedbutnotdead.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://transfixedbutnotdead.com/osd.xml" title="transfixed but not dead!" />
	<atom:link rel='hub' href='http://transfixedbutnotdead.com/?pushpress=hub'/>
		<item>
		<title>Beautiful Perl</title>
		<link>http://transfixedbutnotdead.com/2010/07/16/beautiful-perl/</link>
		<comments>http://transfixedbutnotdead.com/2010/07/16/beautiful-perl/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 19:53:09 +0000</pubDate>
		<dc:creator>draegtun</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://transfixedbutnotdead.com/?p=1062</guid>
		<description><![CDATA[Trying to kill two birds with one stone here. There is a new site called UseTheSource where beautiful or interesting code can be posted. So I thought this might be a good opportunity to get more Modern Perl code across the eyes of the unbelievers So to start the ball rolling I thought I&#8217;d post [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=1062&subd=draegtun&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>Trying to kill two birds with one stone here.  There is a new site called <a href="http://news.usethesource.com/">UseTheSource</a> where <a href="http://news.usethesource.com/item?id=1">beautiful or interesting code</a> can be posted.</p>
<p>So I thought this might be a good opportunity to get more Modern Perl code across the eyes of the unbelievers <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>So to start the ball rolling I thought I&#8217;d post a link to the code used in the Microsoft Winter Scripting Games 2008, as mentioned by chromatic in his <a href="http://www.modernperlbooks.com/mt/2009/02/the-opposite-of-modern.html">The Opposite of Modern</a> post.  </p>
<p>However typically Microsoft they&#8217;ve now broken the links.   And even worse they seemed to have removed all content related to the Scripting Games from their websites <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>Tut tut. Luckily the content can be retrieved via  <a href="http://www.archive.org">WayBackMachine</a>. Here is the <a href="http://web.archive.org/web/20080406121917/http://www.microsoft.com/technet/scriptcenter/funzone/games/solutions08/experlsol01.mspx">article</a> linked in chromatic&#8217;s post.</p>
<p>So while the first bird was to bring UseTheSource to everyones attention, the second bird was to make sure the lost code was resurrected from the dead by saving it here.</p>
<p>This was the challenge:</p>
<blockquote><p>
The first event requires the script to request a 7-digit phone number from the user and then select a corresponding phoneword from the “wordlist.txt” file. The letters in the phone number need to be mapped the same way they are represented on a North American phone dial
</p></blockquote>
<p>And below is the code:</p>
<pre class="brush: perl;">
use strict;
use warnings;

print &quot;Enter 7 digit phone number: &quot;;
chomp(my $number = &lt;&gt;);
die &quot;Invalid number: '$number'\n&quot; unless $number =~ /^\d{7}$/;

my @groups = qw(ABC DEF GHI JKL MNO PRS TUV WXY);
my($letters, $digits);
foreach my $digit (2..9) {
    my $group = $groups[$digit-2];
    $letters .= $group;
    $digits  .= $digit x length($group);
}

open(my $fh, &quot;&lt;&quot;, &quot;C:/Scripts/wordlist.txt&quot;) or die;
while (&lt;$fh&gt;) {
    local $_ = $_;
    eval &quot;tr/$letters\L$letters\E/$digits$digits/&quot;;
    last if /^$number$/o;
}
print uc if defined;
</pre>
<p>This is <a href="http://search.cpan.org/~jdb/">Jan Dubois</a> wonderful idiomatic Perl riposte to (what I believe is) Microsoft&#8217;s <a href="http://web.archive.org/web/20080430174940/http://www.microsoft.com/technet/scriptcenter/funzone/games/solutions08/aplsol01.mspx">original stab</a> at a Perl solution:</p>
<pre class="brush: perl;">
%dictionary = ();

$dictionary{2} = &quot;ABC&quot;;
$dictionary{3} = &quot;DEF&quot;;
$dictionary{4} = &quot;GHI&quot;;
$dictionary{5} = &quot;JKL&quot;;
$dictionary{6} = &quot;MNO&quot;;
$dictionary{7} = &quot;PRS&quot;;
$dictionary{8} = &quot;TUV&quot;;
$dictionary{9} = &quot;WXY&quot;;

open (WordList, &quot;C:\\Scripts\\WordList.txt&quot;);
@arrWordList = &lt;WordList&gt;;
close (WordList);

$strWordList = join(&quot; &quot;, @arrWordList);

print &quot;Please enter the phone number: &quot;;
$phonenumber = &lt;&gt;;

$low = 0;
$high = 3;

do
{
    $strCharacters = &quot;&quot;;

    for ($i = 0; $i &lt; 7; $i++)
        {
            $intValue = substr($phonenumber, $i, 1);
            $letters = $dictionary{$intValue};
            $b = int(rand($high) + $low);
            $substring = substr($letters, $b, 1);
            $strCharacters = $strCharacters . $substring
        }

if ($strWordList =~ m/$strCharacters/i)
    {
        print $strCharacters;
        $x = 1;
    }
}
until $x == 1
</pre>
<p>Proof that <a href="http://www.codinghorror.com/blog/2005/04/you-can-write-fortran-in-any-language.html">you can really write FORTRAN in any language</a> <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>This article is now <a href="http://news.usethesource.com/item?id=415">self referentially posted</a> to UseTheSource.</p>
<p>BTW, If you post a link or code to UseTheSource by Monday, July 19 at 0800 BST then you are in with a <a href="http://news.usethesource.com/item?id=243">chance of winning</a> the &#8220;Beautiful Code&#8221; e-book.  </p>
<p>Hopefully that will give you an incentive to waste a bit of time online this weekend <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>/I3az/</p>
<p>PS. Additionally to this there was another wonderful solution <a href="http://use.perl.org/~gav/journal/35719">posted by Gav</a>.</p>
<p>PPS. Gav also provided a more <a href="http://use.perl.org/~gav/journal/35729">idiomatic solution</a> to Game Event 3.  The original Microsoft solution can be found <a href="http://web.archive.org/web/20080429225510/http://www.microsoft.com/technet/scriptcenter/funzone/games/solutions08/aplsol03.mspx">here</a> on the WayBackMachine (if you dare look!).  I&#8217;ve also posted <a href="http://news.usethesource.com/item?id=416">Gav&#8217;s solution to this</a> on UseSourceCode.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/draegtun.wordpress.com/1062/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/draegtun.wordpress.com/1062/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/draegtun.wordpress.com/1062/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/draegtun.wordpress.com/1062/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/draegtun.wordpress.com/1062/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/draegtun.wordpress.com/1062/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/draegtun.wordpress.com/1062/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/draegtun.wordpress.com/1062/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/draegtun.wordpress.com/1062/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/draegtun.wordpress.com/1062/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=1062&subd=draegtun&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://transfixedbutnotdead.com/2010/07/16/beautiful-perl/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/29cb106071d163d703484e63839d89cb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">draegtun</media:title>
		</media:content>
	</item>
		<item>
		<title>Sequence, Selection and Iteration</title>
		<link>http://transfixedbutnotdead.com/2010/07/05/sequence-selection-and-iteration/</link>
		<comments>http://transfixedbutnotdead.com/2010/07/05/sequence-selection-and-iteration/#comments</comments>
		<pubDate>Mon, 05 Jul 2010 19:34:46 +0000</pubDate>
		<dc:creator>draegtun</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://transfixedbutnotdead.com/?p=1053</guid>
		<description><![CDATA[My bit of procrastination this afternoon was watching this entertaining and interesting keynote from RailsConf 2010 given by Robert Martin. Here is the direct YouTube link Don&#8217;t worry its not Rails or even Ruby loaded. The keynote goes through an interesting history of programming languages and on route Robert mentions Fortran, Lisp, Algol, BASIC, Simula, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=1053&subd=draegtun&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>My bit of procrastination this afternoon was watching this entertaining and interesting keynote from RailsConf 2010 given by <a href="http://www.objectmentor.com/omTeam/martin_r.html">Robert Martin</a>. </p>
<p><span style="text-align:center; display: block;"><a href="http://transfixedbutnotdead.com/2010/07/05/sequence-selection-and-iteration/"><img src="http://img.youtube.com/vi/mslMLp5bQD0/2.jpg" alt="" /></a></span></p>
<p>Here is the direct <a href="http://www.youtube.com/watch?v=mslMLp5bQD0">YouTube link</a></p>
<p>Don&#8217;t worry its not Rails or even Ruby loaded.  The keynote goes through an interesting history of programming languages and on route Robert mentions Fortran, Lisp, Algol, BASIC, Simula, BCPL, B, C, Scheme, Smalltalk, C++, Perl, Java, Ruby, Erlang, C#, F#, Haskell and Clojure.  </p>
<p>Hopefully I didn&#8217;t miss one?   Strangely can&#8217;t recall Python being mentioned!?</p>
<p>/I3az/</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/draegtun.wordpress.com/1053/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/draegtun.wordpress.com/1053/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/draegtun.wordpress.com/1053/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/draegtun.wordpress.com/1053/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/draegtun.wordpress.com/1053/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/draegtun.wordpress.com/1053/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/draegtun.wordpress.com/1053/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/draegtun.wordpress.com/1053/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/draegtun.wordpress.com/1053/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/draegtun.wordpress.com/1053/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=1053&subd=draegtun&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://transfixedbutnotdead.com/2010/07/05/sequence-selection-and-iteration/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/29cb106071d163d703484e63839d89cb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">draegtun</media:title>
		</media:content>

		<media:content url="http://img.youtube.com/vi/mslMLp5bQD0/2.jpg" medium="image" />
	</item>
		<item>
		<title>Very API</title>
		<link>http://transfixedbutnotdead.com/2010/06/25/very-api/</link>
		<comments>http://transfixedbutnotdead.com/2010/06/25/very-api/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 13:39:24 +0000</pubDate>
		<dc:creator>draegtun</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[autobox]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://transfixedbutnotdead.com/?p=1040</guid>
		<description><![CDATA[In my last post about extending autobox::Core, I touched on API choices. So let me expand on this a little bit here and in some more in posts to come. In all bar one of my autobox examples I used $_[0] to pass the iterator object. For eg: ['a'..'z']-&#62;iterate( sub{ print $_[0]-&#62;currentIndex, ' =&#62; ', [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=1040&subd=draegtun&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>In my last post <a href="http://transfixedbutnotdead.com/2010/06/16/each-to-their-own-autobox/">about extending autobox::Core</a>, I touched on API choices.  So let me expand on this a little bit here and in some more in posts to come.</p>
<p>In all bar one of my autobox examples I used $_[0] to pass the iterator object. For eg:</p>
<pre class="brush: perl;">
['a'..'z']-&gt;iterate( sub{
    print $_[0]-&gt;currentIndex, ' =&gt; ', $_[0]-&gt;current;
});
</pre>
<p>But in the last code example I went for $_[0] having the value and $_[1] the iterator object:</p>
<pre class="brush: perl;">
['a'..'z']-&gt;iterate( sub{
    print $_[1]-&gt;currentIndex, ' =&gt; ', $_[0];
});
</pre>
<p>And to help avoid getting cross-eyed with $_[] then this is nicer on the eye if a tad longer:</p>
<pre class="brush: perl;">
['a'..'z']-&gt;iterate( sub{
	my ($v, $iter) = @_;
    print $iter-&gt;currentIndex, ' =&gt; ', $v;
});
</pre>
<p>But hold on, is there a preference to which way round these should be assigned to @_?  Would it be better other way round because value can be got at from the iterator object anyway? (one shift and away!)</p>
<p>So perhaps using $_ is best?</p>
<pre class="brush: perl;">
['a'..'z']-&gt;iterate( sub{
    print $_-&gt;currentIndex, ' =&gt; ', $_-&gt;current;
});
</pre>
<p>I like this a lot.  But it would be amiss not to take advantage of using $_ for the value and $_[0] for iterator so that we can write code like this:</p>
<pre class="brush: perl;">
['a'..'z']-&gt;iterate( sub{
	print $_[0]-&gt;getNext if m/[aeiou]/;
});
</pre>
<p>However note the <code>print $_[0]-&gt;getNext</code> and not just plain <code>print</code>  <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>I don&#8217;t think there is a canonical answer to this but my preference is to use $_ has the iterator object&#8230;  but with probably value &amp; the iterator (again!) passed through @_ (ie. the kitchen sink approach!).</p>
<pre class="brush: perl;">
sub autobox::Core::ARRAY::iterate {
    my ($array, $code) = @_;
    my $iter = Array::Iterator-&gt;new( $array );

    while ($iter-&gt;hasNext) {
        local $_ = $iter;
        $code-&gt;( $iter-&gt;getNext, $iter );
    }

    return wantarray ? @$array : $array;
}
</pre>
<p>Note the <code>return wantarray ? @$array : $array;</code> addition.  This keeps the autobox chaining going and is good adherence to autobox API (though in this iterator context it probably isn&#8217;t of much benefit).</p>
<p>/I3az/</p>
<p>PS.  Let me just add &#8220;Perl&#8221; here because despite lots of perl code snippets I haven&#8217;t mentioned Perl, CPAN or Ironman at all and I&#8217;m still wary whether ironman will pick up the perl tag.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/draegtun.wordpress.com/1040/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/draegtun.wordpress.com/1040/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/draegtun.wordpress.com/1040/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/draegtun.wordpress.com/1040/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/draegtun.wordpress.com/1040/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/draegtun.wordpress.com/1040/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/draegtun.wordpress.com/1040/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/draegtun.wordpress.com/1040/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/draegtun.wordpress.com/1040/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/draegtun.wordpress.com/1040/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=1040&subd=draegtun&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://transfixedbutnotdead.com/2010/06/25/very-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/29cb106071d163d703484e63839d89cb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">draegtun</media:title>
		</media:content>
	</item>
		<item>
		<title>each to their own (autobox)</title>
		<link>http://transfixedbutnotdead.com/2010/06/16/each-to-their-own-autobox/</link>
		<comments>http://transfixedbutnotdead.com/2010/06/16/each-to-their-own-autobox/#comments</comments>
		<pubDate>Wed, 16 Jun 2010 10:09:19 +0000</pubDate>
		<dc:creator>draegtun</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[autobox]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://transfixedbutnotdead.com/?p=1024</guid>
		<description><![CDATA[If you are a bit wary of using each on an @array then perhaps using autobox maybe more to your taste? Because autobox::Core comes with three looping methods: each foreach for each iterates over a hash and works exactly the same as the perl function each (because internally it uses each so same caveats apply [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=1024&subd=draegtun&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>If you are a bit wary of using <a href="http://transfixedbutnotdead.com/2010/06/06/each-array-in-perl-5-12/">each on an @array</a> then perhaps using <a href="http://search.cpan.org/dist/autobox">autobox</a> maybe more to your taste?  Because <a href="http://search.cpan.org/dist/autobox-Core/">autobox::Core</a> comes with three looping methods:</p>
<ul>
<li>each</li>
<li>foreach</li>
<li>for</li>
</ul>
<p><i>each</i> iterates over a hash and works exactly the same as the perl function <a href="http://perldoc.perl.org/functions/each.html">each</a> (because internally it uses <a href="http://perldoc.perl.org/functions/each.html">each</a> so same caveats apply that I mentioned in my <a href="http://transfixedbutnotdead.com/2010/06/06/each-array-in-perl-5-12/">last post</a>).</p>
<pre class="brush: perl;">
%hash-&gt;each( sub{
	my ($k, $v) = @_;
	say &quot;$k = $v&quot;;
});
</pre>
<p>The other two methods work on arrays:</p>
<pre class="brush: perl;">
my @array = ('a'..'z');

@array-&gt;foreach(sub { say $_[0] });

@array-&gt;for( sub{
	my ($index, $value) = @_;
	say &quot;$index : $value&quot;;
});
</pre>
<p><i>foreach</i> just provides the current element.  Whereas <i>for</i> works in similar way to how the <a href="http://perldoc.perl.org/functions/each.html">each</a> function on an array.  However it also provides the array ref which allows us to repeat my &#8220;vowel&#8221; snippet from <a href="http://transfixedbutnotdead.com/2010/06/06/each-array-in-perl-5-12/">last post</a> in autobox like so:</p>
<pre class="brush: perl;">
use 5.012;
use warnings;
use autobox::Core;

my @tokens = 'a' .. 'z';

@tokens-&gt;for( sub{
    my ($i, $v, $array) = @_;
    if ($v =~ m/[aeiou]/) {
        print $array-&gt;[ $i + 1 ];    # peeks ahead into @tokens
    }
});

# =&gt; bfjpv
</pre>
<p>OK thats not quite the same because my function <a href="http://perldoc.perl.org/functions/each.html">each</a> snippet in <a href="http://transfixedbutnotdead.com/2010/06/06/each-array-in-perl-5-12/">last post</a> was more optimal because it moved to next iteration in the array so saving a pass in the loop.  Stayed tuned because i&#8217;ll come back to this later.</p>
<p>So what about my <i>last</i> caveat from previous post?   Well <i>foreach &amp; for</i> do not use the <a href="http://perldoc.perl.org/functions/each.html">each</a> function so its not a problem!</p>
<pre class="brush: perl;">
@tokens-&gt;for( sub{
    my ($i, $v, $array) = @_;
    print $v;
    last  if $i == 12;
});

# =&gt; abcdefghijklm
</pre>
<p>However (potential caveat <a href="http://perldoc.perl.org/perllexwarn.html">warning!</a>) you will get a <i>Exiting subroutine via last at&#8230;</i> warning when using above <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>This can be fixed:</p>
<pre class="brush: perl;">
@tokens-&gt;for( sub{
    my ($i, $v, $array) = @_;
    print $v;
    if ($i == 12) {
        no warnings 'exiting';
        last;
    }
});
</pre>
<p>But I get the feeling I&#8217;ve brushed something under the carpet here!</p>
<p>So perhaps time to add a method to autobox::Core then:</p>
<pre class="brush: perl;">
sub autobox::Core::ARRAY::whileTrue {
    my ($array, $code) = @_; 

    for (my $i = 0; $i &lt;= $#$array; $i++) {
        my $return = $code-&gt;( $i, $array-&gt;[$i], $array );
        last unless $return;
    }
}

# now go thru @tokens unless the block returns false value

@tokens-&gt;whileTrue( sub{
    my ($i, $v, $array) = @_;
    print $v;
    return 0 if $i == 12;
    1;   # &lt;= always remember this!
});
</pre>
<p>Hmmm&#8230; OK it works but is a bit hacky! (even wacky!!).  </p>
<p>But something is needed because otherwise it will just iterate through whole array. So a much better way is to integrate something like the <a href="http://search.cpan.org/dist/Array-Iterator/">Array::Iterator</a> CPAN module that I mentioned in the comments of my <a href="http://transfixedbutnotdead.com/2010/06/06/each-array-in-perl-5-12/">last post</a>:</p>
<pre class="brush: perl;">
sub autobox::Core::ARRAY::iterate {
    my ($array, $code) = @_;
    my $iter = Array::Iterator-&gt;new( $array );

    while ($iter-&gt;hasNext) {
        $iter-&gt;getNext;
        $code-&gt;( $iter );
    }
}
</pre>
<p>Now lets first jump back a bit and see how this works with my original snippets:</p>
<pre class="brush: perl;">
@tokens-&gt;iterate( sub{
    # index =&gt; value
    print $_[0]-&gt;currentIndex, ' =&gt; ', $_[0]-&gt;current;
});

@tokens-&gt;iterate( sub{
    # print next token after a vowel
    print $_[0]-&gt;getNext  if $_[0]-&gt;current =~ m/[aeiou]/;
});
</pre>
<p>Wonderbar!  And because we are using a full blown iterator it now pulls the next element off the array (see getNext method) just like function <a href="http://perldoc.perl.org/functions/each.html">each</a> but without any of the side effects!</p>
<p>So for <i>last</i>, its just a matter of subclassing of Array::Iterator with a <i>last</i> method:</p>
<pre class="brush: perl;">
use 5.012;
use warnings;
use autobox::Core;

{
    package Array::Iterator::Last;
    use parent 'Array::Iterator';

    sub last {
        my ($self) = @_;
        $self-&gt;_current_index = $self-&gt;getLength;
    }
}

sub autobox::Core::ARRAY::iterate {
    my ($array, $code) = @_;
    my $iter = Array::Iterator::Last-&gt;new( $array );

    while ($iter-&gt;hasNext) {
        $code-&gt;($iter-&gt;getNext, $iter);
    }
}

['a'..'z']-&gt;iterate( sub{
    my ($val, $iter) = @_;
    print $val;
    $iter-&gt;last  if $iter-&gt;currentIndex == 12;
});
</pre>
<p>And bob&#8217;s your uncle <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>NB. Now the keen eyed among you may have noticed that this time I passed both the element and the iterator object to the callback.  Even with just methods, <a href="http://en.wikipedia.org/wiki/Application_programming_interface">API</a> choices are never easy!  More on this in my next post.</p>
<p>/I3az/</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/draegtun.wordpress.com/1024/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/draegtun.wordpress.com/1024/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/draegtun.wordpress.com/1024/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/draegtun.wordpress.com/1024/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/draegtun.wordpress.com/1024/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/draegtun.wordpress.com/1024/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/draegtun.wordpress.com/1024/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/draegtun.wordpress.com/1024/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/draegtun.wordpress.com/1024/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/draegtun.wordpress.com/1024/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=1024&subd=draegtun&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://transfixedbutnotdead.com/2010/06/16/each-to-their-own-autobox/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/29cb106071d163d703484e63839d89cb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">draegtun</media:title>
		</media:content>
	</item>
		<item>
		<title>each @array in Perl 5.12</title>
		<link>http://transfixedbutnotdead.com/2010/06/06/each-array-in-perl-5-12/</link>
		<comments>http://transfixedbutnotdead.com/2010/06/06/each-array-in-perl-5-12/#comments</comments>
		<pubDate>Sun, 06 Jun 2010 15:11:47 +0000</pubDate>
		<dc:creator>draegtun</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://transfixedbutnotdead.com/?p=1012</guid>
		<description><![CDATA[Don&#8217;t recall seeing anyone blog about it and in fact the documentation is pretty sparse but from Perl 5.12 each can now iterate over an array like so: use 5.012; use warnings; my @array = 'a' .. 'h'; while (my ($i, $val) = each @array) { say &#34;$i =&#62; $val&#34;; } each on an array [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=1012&subd=draegtun&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>Don&#8217;t recall seeing anyone blog about it and in fact the documentation is pretty sparse but from Perl 5.12 <i>each</i> can now iterate over an array like so:</p>
<pre class="brush: perl;">
use 5.012;
use warnings;

my @array = 'a' .. 'h';

while (my ($i, $val) = each @array) {
    say &quot;$i =&gt; $val&quot;;
}
</pre>
<p><i>each</i> on an array returns two values&#8230;  the index and the value of the current iteration.  Thus we get this output from above code:</p>
<pre>
  0 =&gt; a
  1 =&gt; b
  2 =&gt; c
  3 =&gt; d
  4 =&gt; e
  5 =&gt; f
  6 =&gt; g
  7 =&gt; h
</pre>
<p>Anyway to save me thinking up a blog post please excuse me while I just regurgitate my <a href="http://stackoverflow.com/questions/2979741/can-i-pull-the-next-element-from-within-a-perl-foreach-loop/2984326#2984326">Stackoverflow answer I gave earlier today</a> about using <i>each</i> with an array:</p>
<p>==start==<br />
Starting with Perl 5.12, <a href="http://perldoc.perl.org/perl5120delta.html#each-is-now-more-flexible">each is now more flexible</a> by also working on arrays:</p>
<pre class="brush: perl;">
use 5.012;
use warnings;

my @tokens = 'a' .. 'z';

while (my ($i, $val) = each @tokens) {
    if ($val =~ m/[aeiou]/) {
        ($i, $val) = each @tokens;   # get next token after a vowel
        print $val;
    }
}

# =&gt; bfjpv
</pre>
<p>One caveat with <a href="http://perldoc.perl.org/functions/each.html">each</a>, remember the iterator is global and is not reset if you break out of a loop.</p>
<p>For eg:</p>
<pre class="brush: perl;">
while (my ($i, $val) = each @tokens) {
    print $val;
    last if $i == 12;
}

# =&gt; abcdefghijklm

my ($i, $val) = each @tokens;
say &quot;Now at =&gt; $val ($i)&quot;;         # Now at =&gt; n (13)
</pre>
<p>So use <a href="http://perldoc.perl.org/functions/keys.html">keys</a> or <a href="http://perldoc.perl.org/functions/values.html">values</a> to manually reset the iterator:</p>
<pre class="brush: perl;">
keys @tokens;                      # resets iterator
($i, $val) = each @tokens;
say &quot;Now at =&gt; $val ($i)&quot;;         # Now at =&gt; a (0)
</pre>
<p>==end==</p>
<p>I&#8217;ve just come back from a nice weeks break&#8230;   so I&#8217;m still a lazy git in holiday mode here <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
<p>/I3az/</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/draegtun.wordpress.com/1012/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/draegtun.wordpress.com/1012/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/draegtun.wordpress.com/1012/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/draegtun.wordpress.com/1012/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/draegtun.wordpress.com/1012/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/draegtun.wordpress.com/1012/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/draegtun.wordpress.com/1012/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/draegtun.wordpress.com/1012/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/draegtun.wordpress.com/1012/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/draegtun.wordpress.com/1012/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=1012&subd=draegtun&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://transfixedbutnotdead.com/2010/06/06/each-array-in-perl-5-12/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/29cb106071d163d703484e63839d89cb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">draegtun</media:title>
		</media:content>
	</item>
		<item>
		<title>Where did it go?</title>
		<link>http://transfixedbutnotdead.com/2010/05/27/where-did-it-go/</link>
		<comments>http://transfixedbutnotdead.com/2010/05/27/where-did-it-go/#comments</comments>
		<pubDate>Thu, 27 May 2010 21:33:04 +0000</pubDate>
		<dc:creator>draegtun</dc:creator>
				<category><![CDATA[Blogging]]></category>
		<category><![CDATA[ironman]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://transfixedbutnotdead.com/?p=1001</guid>
		<description><![CDATA[My last post a couple of days ago, What I Would Like To See, seemed to have hit the Ironman bitbucket There is no mention of Perl in the article (a first for me for probably over a year!). But it is tagged with &#8220;perl&#8221; and &#8220;ironman&#8221;. Is there an issue with WordPress tags? Is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=1001&subd=draegtun&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>My last post a couple of days ago, <a href="http://transfixedbutnotdead.com/2010/05/25/what-i-would-like-to-see/">What I Would Like To See</a>, seemed to have hit the Ironman bitbucket <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>There is no mention of Perl in the article (a first for me for probably over a year!).   But it is tagged with &#8220;perl&#8221; and &#8220;ironman&#8221;.  Is there an issue with WordPress tags?  Is ironman only seeing WordPress categories (which were &#8220;blogging&#8221; and &#8220;programming&#8221; for this post).</p>
<p>Thought I better check what my WordPress RSS feed is spewing out using <a href="http://search.cpan.org/dist/XML-Feed/">XML::Feed</a>:</p>
<pre class="brush: perl;">
use 5.012;
use warnings;
use XML::Feed;

my $feed = XML::Feed-&gt;parse(URI-&gt;new('http://transfixedbutnotdead.com/feed'))
    or die XML::Feed-&gt;errstr;

for my $entry ($feed-&gt;entries) {
    say $entry-&gt;title;
    for my $category ($entry-&gt;category) {
        say &quot;\t&quot;, $category;
    }
}
</pre>
<p>What came back was this:</p>
<pre>
	What I Would Like To See
		Blogging
		Programming
		perl
		ironman
	Perl block with lexically-scoped method delegation
		Programming
		perl
		Devel::Declare
		dsl
	PDL advert get its 15 minutes of fame!
		Programming
		PDL
		perl
		stackoverflow
	Perlcast website is back
		Blogging
		Programming
		perl
		perlcast
	Podcasts &amp; Perl
		Programming
		perl
		podcast
	Famous Perl programmers
		Programming
		perl
		python
		django
	Caralyst 5.8: The Perl MVC Framework
		Programming
		catalyst
		perl
	Perl ads on Stackoverflow
		Programming
		perl
		stackoverflow
	Two questions… similar answers… same module
		Programming
		moose
		perl
	The unlikely intersection of Boy George and Damian Conway
		Programming
		london.pm
		perl
</pre>
<p>Both the WordPress tags &amp; categories were coming through has RSS categories.  I believe this is correct so why hasn&#8217;t Ironman picked up the &#8220;What I Would Like To See&#8221; post?   </p>
<p>So is having Perl, CPAN or ironman in the content mandatory?</p>
<p>/I3az/</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/draegtun.wordpress.com/1001/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/draegtun.wordpress.com/1001/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/draegtun.wordpress.com/1001/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/draegtun.wordpress.com/1001/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/draegtun.wordpress.com/1001/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/draegtun.wordpress.com/1001/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/draegtun.wordpress.com/1001/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/draegtun.wordpress.com/1001/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/draegtun.wordpress.com/1001/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/draegtun.wordpress.com/1001/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=1001&subd=draegtun&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://transfixedbutnotdead.com/2010/05/27/where-did-it-go/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/29cb106071d163d703484e63839d89cb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">draegtun</media:title>
		</media:content>
	</item>
		<item>
		<title>What I Would Like To See</title>
		<link>http://transfixedbutnotdead.com/2010/05/25/what-i-would-like-to-see/</link>
		<comments>http://transfixedbutnotdead.com/2010/05/25/what-i-would-like-to-see/#comments</comments>
		<pubDate>Tue, 25 May 2010 22:07:11 +0000</pubDate>
		<dc:creator>draegtun</dc:creator>
				<category><![CDATA[Blogging]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[ironman]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://transfixedbutnotdead.com/?p=993</guid>
		<description><![CDATA[I think I would love to see mst present a YAPC talk on Catalyst, Rails &#38; Django &#8211; the shootout! No web framework is perfect so I think it maybe insightful to highlight the best &#38; worst features of all these frameworks and see how they stack up against each other. And to provide complete [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=993&subd=draegtun&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>I think I would love to see <a href="http://shadowcat.co.uk/blog/matt-s-trout/">mst</a> present a YAPC talk on <a href="http://shadowcat.co.uk/blog/matt-s-trout/iron-man-lost?colour=black+red+green&amp;title=catalyst+rails+django+shootout">Catalyst, Rails &amp; Django &#8211; the shootout!</a></p>
<p>No web framework is perfect so I think it maybe insightful to highlight the best &amp; worst features of all these frameworks and see how they stack up against each other.</p>
<p>And to provide complete impartiality for the talk then I think the hair colour should be a mixture of green for <a href="http://www.djangoproject.com/">django</a>, red for <a href="http://rubyonrails.org/">rails</a> and eh, not sure what colour for <a href="http://www.catalystframework.org/">catalyst</a>?&#8230; so lets stick to mst&#8217;s natural hair colour for that <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>/I3az/</p>
<p>PS. BTW&#8230; if you think my multi-colour choice was a bit OTT, then its fortunate I didn&#8217;t go with my original thought of suggesting using the colours of my favourite Rugby &amp; Footie teams!   That would have been eye catching mix of black &amp; gold for <a href="http://www.wasps.co.uk/">London Wasps</a> and the blue &amp; white <a href="http://www.qpr.co.uk">Superhoops</a> <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/draegtun.wordpress.com/993/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/draegtun.wordpress.com/993/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/draegtun.wordpress.com/993/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/draegtun.wordpress.com/993/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/draegtun.wordpress.com/993/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/draegtun.wordpress.com/993/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/draegtun.wordpress.com/993/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/draegtun.wordpress.com/993/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/draegtun.wordpress.com/993/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/draegtun.wordpress.com/993/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=993&subd=draegtun&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://transfixedbutnotdead.com/2010/05/25/what-i-would-like-to-see/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/29cb106071d163d703484e63839d89cb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">draegtun</media:title>
		</media:content>
	</item>
		<item>
		<title>Perl block with lexically-scoped method delegation</title>
		<link>http://transfixedbutnotdead.com/2010/05/15/perl-block-with-lexically-scoped-method-delegation/</link>
		<comments>http://transfixedbutnotdead.com/2010/05/15/perl-block-with-lexically-scoped-method-delegation/#comments</comments>
		<pubDate>Sat, 15 May 2010 14:00:45 +0000</pubDate>
		<dc:creator>draegtun</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[Devel::Declare]]></category>
		<category><![CDATA[dsl]]></category>

		<guid isPermaLink="false">http://transfixedbutnotdead.com/?p=980</guid>
		<description><![CDATA[About a year ago I came across this interesting Ruby blog post Keyword With. This is something I always wanted in Perl and immediately marked a note in my list of blog/CPAN ideas with &#8220;Devel::Declare and with statement&#8221; (with side note that &#8220;using&#8221; might be more appropriate so not to clash with Moose roles sugar). [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=980&subd=draegtun&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>About a year ago I came across this interesting Ruby blog post <a href="http://www.ironicwolf.com/2009/05/keyword-with/">Keyword With</a>.  </p>
<p>This is something I always wanted in Perl and immediately marked a note in my list of blog/CPAN ideas with &#8220;Devel::Declare and with statement&#8221; (with side note that &#8220;using&#8221; might be more appropriate so not to clash with Moose roles sugar).</p>
<p>Unsurprisingly this just languished in my ever increasing list <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />   </p>
<p>However last month I had a few hours spare one weekend so pulled out my laptop and rummaged through my list and decided to see how difficult it would be to implement &#8220;with&#8221;.</p>
<p>Unfortunately I kept hitting brick walls with <a href="http://perldoc.perl.org/functions/local.html">local</a> scoping.  I came to conclusion that I may have to use <a href="http://perldoc.perl.org/functions/eval.html">eval</a> or even go down a different track using an AUTOLOAD solution.</p>
<p>I left that weekend experiment with at least a very basic AUTOLOAD proof of concept:</p>
<pre class="brush: perl;">
use 5.012;
use warnings;

{
    package FileStuff;
    use Moose;

    has name =&gt; ( is =&gt; 'rw', isa =&gt; 'Str' );

    sub save { say &quot;save &quot;,   $_[0]-&gt;name }

    sub del  { say &quot;delete &quot;, $_[0]-&gt;name }

    sub mv {
        my ($self, $to) = @_;
        say &quot;rename &quot;, $self-&gt;name, &quot; to $to&quot;;
        $self-&gt;name( $to );
    }

    sub say { say &quot;Method say: &quot;, @_ }
}

my $f = FileStuff-&gt;new( name =&gt; 'foobar' );

# using $f {}
{
    local *AUTOLOAD = sub {
        our $AUTOLOAD;
        my $name = (split '::', $AUTOLOAD)[-1];
        die &quot;method $name NOT FOUND!&quot; unless $f-&gt;can( $name );
        $f-&gt;$name( @_ );
    };

    # my &quot;DSL&quot; stuff!
    save();               # $f-&gt;save();
    mv( &quot;barbaz&quot; );       # $f-&gt;mv( &quot;barbaz&quot; );
    del();                # parenthesis are always required
    say( &quot;builtin say&quot; ); # builtin wins over $f-&gt;say
}
</pre>
<p>I wasn&#8217;t sure if this would ever evolve into a robust solution.  However I found it reassuring to note that other people had similar problems trying to use local scoping in similar way when I came across this Perlmonks post <a href="http://perlmonks.org/?node_id=834137">A useful use of goto</a> a few days later.  So this gave the AUTOLOAD approach some merit.</p>
<p>Well chances are this blog post or any additional development may never made it any further.  What changed that was an email from <a href="http://search.cpan.org/~chocolate/">chocolateboy</a> this morning pointing me at his new <a href="http://search.cpan.org/dist/Scope-With/">Scope::With</a> CPAN module.</p>
<p>Blimey&#8230; Father Christmas had delivered my xmas pressie early and without even seeing my xmas list <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>chocolateboy&#8217;s first example of Scope::With even shows how it works with my <a href="http://search.cpan.org/dist/Builder/">Builder</a> module:</p>
<pre class="brush: perl;">
use Builder;
use Scope::With;

my $builder = Builder-&gt;new();
my $xml = $builder-&gt;block('Builder::XML');

with ($xml) {
    body(
        div(
            span({ id =&gt; 1 }, 'one'),
            span({ id =&gt; 2 }, 'two'),
        )
    );
}

say $builder-&gt;render();
</pre>
<p>Which is exactly why I wanted a &#8220;with&#8221; statement in Perl and it looked like chocolateboy also felt the same!</p>
<p>The documentation even gave an &#8220;using&#8221; example:</p>
<pre class="brush: perl;">
use Scope::With qw(using);

using ($xml) {
    div(
        span( ... ),
        span( ... ),
    );
}
</pre>
<p>Getting worried now someone was reading my mind <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>This is truly awesome stuff. chocolateboy has the habit of producing game changing CPAN modules. For eg. <a href="http://search.cpan.org/dist/autobox/">autobox</a> and <a href="http://search.cpan.org/dist/Method-Lexical/">Method::Lexical</a>.  To me <a href="http://search.cpan.org/dist/Scope-With/">Scope::With</a> is potentially another one that falls into this lofty category.  </p>
<p>I&#8217;m deeply honoured to find my Builder module being referenced and also glad to see that a &#8220;with&#8221; statement using <a href="http://search.cpan.org/dist/Devel-Declare/">Devel::Declare</a> and AUTOLOAD isn&#8217;t such a delusional idea <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>So many thanks to chocolateboy for writing Scope::With.  Keep up the good work.</p>
<p>/I3az/</p>
<p>PS. chocolateboy&#8217;s Scope::With docs also references a prior art module <a href="http://search.cpan.org/dist/with/">with</a> by <a href="http://search.cpan.org/~vpit/">Vincent Pit</a>. This module achieves similar things but in different way/implementation.</p>
<p>PPS. CPAN is so big and wonderful that its easy to miss or even forget whats on there!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/draegtun.wordpress.com/980/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/draegtun.wordpress.com/980/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/draegtun.wordpress.com/980/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/draegtun.wordpress.com/980/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/draegtun.wordpress.com/980/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/draegtun.wordpress.com/980/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/draegtun.wordpress.com/980/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/draegtun.wordpress.com/980/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/draegtun.wordpress.com/980/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/draegtun.wordpress.com/980/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=980&subd=draegtun&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://transfixedbutnotdead.com/2010/05/15/perl-block-with-lexically-scoped-method-delegation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/29cb106071d163d703484e63839d89cb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">draegtun</media:title>
		</media:content>
	</item>
		<item>
		<title>PDL advert get its 15 minutes of fame!</title>
		<link>http://transfixedbutnotdead.com/2010/05/06/pdl-advert-get-its-15-minutes-of-fame/</link>
		<comments>http://transfixedbutnotdead.com/2010/05/06/pdl-advert-get-its-15-minutes-of-fame/#comments</comments>
		<pubDate>Thu, 06 May 2010 10:10:02 +0000</pubDate>
		<dc:creator>draegtun</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[stackoverflow]]></category>
		<category><![CDATA[PDL]]></category>

		<guid isPermaLink="false">http://transfixedbutnotdead.com/?p=972</guid>
		<description><![CDATA[You may recall that I added the PDL (Perl Data Language) logo to Stackoverflow opensource ads recently. Well the logo achieved its 15 minutes of glory when it was fortuitously screen captured for the following ReadWriteWeb article about Stackoverflow raising venture capital: http://www.readwriteweb.com/archives/stackoverflow_business_funding.php Well done to all those of you voted this up to make [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=972&subd=draegtun&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>You may recall that I added the  <a href="http://transfixedbutnotdead.com/2010/04/10/perl-ads-on-stackoverflow/">PDL (Perl Data Language) logo</a> to Stackoverflow opensource ads <a href="http://meta.stackoverflow.com/questions/31913/open-source-advertising-sidebar-1h-2010">recently</a>.</p>
<p>Well the logo achieved its 15 minutes of glory when it was fortuitously  screen captured for the following <a href="http://www.readwriteweb.com">ReadWriteWeb</a> article about Stackoverflow raising venture capital:</p>
<ul>
<li><a href="http://www.readwriteweb.com/archives/stackoverflow_business_funding.php">http://www.readwriteweb.com/archives/stackoverflow_business_funding.php</a></li>
</ul>
<p>Well done to all those of you voted this up to make this happen <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>NB. This is the <a href="http://news.ycombinator.com/item?id=1318457">Hacker News post</a> which pointed me to the ReadWriteWeb article.</p>
<p>/I3az/</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/draegtun.wordpress.com/972/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/draegtun.wordpress.com/972/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/draegtun.wordpress.com/972/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/draegtun.wordpress.com/972/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/draegtun.wordpress.com/972/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/draegtun.wordpress.com/972/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/draegtun.wordpress.com/972/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/draegtun.wordpress.com/972/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/draegtun.wordpress.com/972/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/draegtun.wordpress.com/972/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=972&subd=draegtun&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://transfixedbutnotdead.com/2010/05/06/pdl-advert-get-its-15-minutes-of-fame/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/29cb106071d163d703484e63839d89cb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">draegtun</media:title>
		</media:content>
	</item>
		<item>
		<title>Perlcast website is back</title>
		<link>http://transfixedbutnotdead.com/2010/05/04/perlcast-website-is-back/</link>
		<comments>http://transfixedbutnotdead.com/2010/05/04/perlcast-website-is-back/#comments</comments>
		<pubDate>Tue, 04 May 2010 19:14:58 +0000</pubDate>
		<dc:creator>draegtun</dc:creator>
				<category><![CDATA[Blogging]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[perlcast]]></category>

		<guid isPermaLink="false">http://transfixedbutnotdead.com/?p=963</guid>
		<description><![CDATA[Good news, Perlcast is back from the GoDaddy grave Bad news, The Perl Report which I list on my blog links as now disappeared Fingers crossed The Perl Report is only a temporary issue. And touch wood Perlcast can return to more regular podcasts (perhaps its something that TPF can look into has part of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=963&subd=draegtun&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>Good news, <a href="http://perlcast.com">Perlcast</a> is back from the <a href="http://transfixedbutnotdead.com/2010/04/30/podcasts-perl/">GoDaddy grave</a> <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Bad news, <a href="http://www.theperlreport.com/">The Perl Report</a> which I list on my blog links as now disappeared <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>Fingers crossed The Perl Report is only a temporary issue.   And touch wood Perlcast can return to more regular podcasts (perhaps its something that <a href="http://www.perlfoundation.org/">TPF</a> can look into has part of their promoting  Perl?)</p>
<p>/I3az/</p>
<p>PS.  Some blog house keeping:</p>
<ul>
<li>Removed <a href="http://use.perl.org">use Perl;</a> from my link list.  Not much going on their front page these days and it doesn&#8217;t look very appealing if you go there with no login/profile.</li>
<li>Added <a href="http://yapc.tv/">YAPC TV</a> to my link list.</li>
<li>And also <a href="http://www.presentingperl.org/">Presenting Perl</a></li>
<li>And yes there are no ironman badges at moment (since ironman site upgrade)</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/draegtun.wordpress.com/963/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/draegtun.wordpress.com/963/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/draegtun.wordpress.com/963/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/draegtun.wordpress.com/963/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/draegtun.wordpress.com/963/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/draegtun.wordpress.com/963/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/draegtun.wordpress.com/963/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/draegtun.wordpress.com/963/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/draegtun.wordpress.com/963/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/draegtun.wordpress.com/963/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=963&subd=draegtun&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://transfixedbutnotdead.com/2010/05/04/perlcast-website-is-back/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/29cb106071d163d703484e63839d89cb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">draegtun</media:title>
		</media:content>
	</item>
	</channel>
</rss>