stvn_skuo's Journal stvn_skuo's use Perl Journal en-us use Perl; is Copyright 1998-2006, Chris Nandor. Stories, comments, journals, and other submissions posted on use Perl; are Copyright their respective owners. 2012-01-25T02:39:20+00:00 pudge Technology hourly 1 1970-01-01T00:00+00:00 stvn_skuo's Journal Nevermind <br> I think the xml files that were there in <tt>blib</tt> came from my having used <em>EUMM</em> earlier.<br> <br> Note to self: Already run <tt>realclean</tt> when switching from <em>ExtUtils::MakeMaker</em> to <em>Module::Build</em>. stvn_skuo 2005-10-25T04:58:58+00:00 journal Module::Build weirdness <br> I would have sworn that <em>Module::Build</em> had been doing "the right thing" all along.<br> <br> Given<blockquote><div><p> <tt>lib/Foo/foo.PL</tt></p></div> </blockquote><p>and</p><blockquote><div><p> <tt>PL_files =&gt; {<br>&nbsp; &nbsp;'lib/Foo/foo.PL' =&gt; 'lib/Foo/foo.xml',<br>}</tt></p></div> </blockquote><p> I saw it copy <tt>foo.xml</tt> into the <tt>blib</tt> directory, etc.<br> <br> I added one more item to PL_files, re-ran <tt>Build.PL</tt>, re-ran my tests, and all of a sudden the xml files were no longer being copied into <tt>blib</tt> thus causing tests to fail.<br> <br> No worries as all was well again after I added</p><blockquote><div><p> <tt>$builder-&gt;add_build_element('xml');</tt></p></div> </blockquote> stvn_skuo 2005-10-24T20:54:17+00:00 journal MREs -- now with steroids... <br> <br> Years ago, after graduating from high school, I considered joining the Marines as a means of getting a college education. &nbsp;&nbsp; I went to the recruiting office and took the "written test" and was scheduled to take a physical exam weeks later. &nbsp;&nbsp; The timely arrival of a college acceptance letter with an offer of a scholarship diverted me away from the military.<br> <br> Thinking back, I doubt I would have made it through boot camp. &nbsp;&nbsp; I was fit and trim from having been on the swim team but I never did have the physique for any "real combat".<br> <br> At the <em>Tomb of the Unknown Soldier</em> in Arlington National Cemetery, when I visited there on vacation, I saw The. Biggest. Guard. Ever. &nbsp;&nbsp; He had a shaved head, crisp uniform, big stompy boots -- except that he barely made any sound as he patrolled back and forth -- and precise turns made while carrying a rifle. &nbsp;&nbsp; Not the rat-tat-tat automatic weapon kind of rifle -- the kind with bolt-action that makes a satisfying click-click sound (or so I imagine from seeing countless action movies, as I've never fired a gun).<br> <br> What brought this to mind was seeing the funeral procession of William Rehnquist, the late Supreme Court Justice, on television this morning.&nbsp;&nbsp; His pall bearers were his former clerks. I'm not saying all his clerks eventually found desk jobs where their daily routine now involve lifting items no heavier than a briefcase -- I'll just say that they seem a bit strained while transporting the casket. &nbsp;&nbsp;Contrast that to the funeral of Ronald Reagan, the 40th President, whose coffin was carried, seemingly effortlessly, by marching military guards.<br> <br> Either the recruiters for the armed forces have a great screening process to pick out the biggest, strongest guys, or they're putting steroids into MREs (yup, steroids). stvn_skuo 2005-09-07T04:33:53+00:00 journal Just in time Thanks <a href=""> rafael</a>.&nbsp;&nbsp; I was just looking for a way to compare files as strings and found File::Compare a bit lacking. <br> <br> Looks like someone else besides me would like an option to ignore <a href=""> differences in number of whitespaces</a>. &nbsp;&nbsp;Other options I often use with the Unix <em>diff</em> utility include those to <ul> <li> ignore differences between lower- and upper-case letters, and </li><li> expand tabs to whitespace.</li></ul><p> I suppose I could preprocess the strings before handing them off to <tt>is_string()</tt>:</p><blockquote><div><p> <tt>use Text::Tabs;<br>use Test::More tests =&gt; 1;<br>use Test::LongString;<br> <br># Apply one or more filters.<br># N.B. The order in which the filters are applied matters:<br> <br>my @strings =<br>&nbsp; &nbsp; map {tr/\n\r\f /<nobr> <wbr></nobr>/s; $_}<br>&nbsp; &nbsp; map expand($_) =&gt;<br>&nbsp; &nbsp; map lc($_)&nbsp; &nbsp; &nbsp;=&gt;<br>&nbsp; &nbsp; &lt;DATA&gt;;<br> <br>is_string(<br>&nbsp; &nbsp; $strings[0],<br>&nbsp; &nbsp; $strings[1],<br>&nbsp; &nbsp; 'Actually differs by one char'<br>);<br> <br>__DATA__<br>This is a test of Test::LongStrings<br>this&nbsp; &nbsp; is a&nbsp; &nbsp; test&nbsp; &nbsp; &nbsp;of Test::longstring</tt></p></div> </blockquote><p> As far as the <tt>_common_prefix_length</tt> function is concerned, perhaps using <tt>substr</tt> would be a bit faster?</p><blockquote><div><p> <tt>&nbsp; &nbsp; &nbsp;while (length($x) &amp;&amp; length($y)) {<br>-&nbsp; &nbsp; &nbsp; &nbsp;my ($x1,$x2) = $x =~<nobr> <wbr></nobr>/(.)(.*)/s;<br>-&nbsp; &nbsp; &nbsp; &nbsp;my ($y1,$y2) = $y =~<nobr> <wbr></nobr>/(.)(.*)/s;<br>+&nbsp; &nbsp; &nbsp; &nbsp; my $x1 = substr($x, 0, 1, '');<br>+&nbsp; &nbsp; &nbsp; &nbsp; my $y1 = substr($y, 0, 1, '');<br>&nbsp; &nbsp; &nbsp; &nbsp; if ($x1 eq $y1) {<br>-&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$x = $x2;<br>-&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$y = $y2;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ++$r;<br>&nbsp; &nbsp; &nbsp; &nbsp; }</tt></p></div> </blockquote> stvn_skuo 2005-08-05T06:13:54+00:00 journal Superbowl Sunday I wonder how long it'll take before the Patriots' logo appears above the "use Perl;" banner... stvn_skuo 2005-02-06T15:57:40+00:00 journal slowly going through perlapi Notes to self:<ul> <li>With Inline::C, arguments to variadic C functions should be processed with <tt>Inline_Stack_Item(s)</tt>, instead of the functions declared in <tt>&lt;stdarg.h&gt;</tt>.</li> <li>Calling Perl subroutines from C? Better start reading <i>perlguts</i>, <i>perlapi</i>, and <i>perlcall</i>.</li> </ul><p> I don't do any XS programming, but I do use C often enough to think learning Inline to be worthwhile and, well, fun. After my first experience with Inline, I really have to give kudos to those in<nobr> <wbr></nobr><tt>/p\d+p/</tt> who so deftly handle three disciplines (e.g, Perl, C, and XS).</p><p> My first naive attempt went something like this:</p><blockquote><div><p> <tt>use Inline 'C';<br> <br>my @integers = (4, 2, 1, 5, 6, 3);<br> <br>print +choose(\&amp;lessthan, scalar @integers, @integers);<br>print +choose(\&amp;grtrthan, scalar @integers, @integers);<br> <br>__DATA__<br>__C__<br> <br>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br>#include &lt;stdarg.h&gt;<br> <br>int lessthan (int a, int b)<br>{<br>&nbsp; &nbsp; return (a &lt; b) ? a : b;<br>}<br>int grtrthan (int a, int b)<br>{<br>&nbsp; &nbsp; return (a &gt; b) ? a : b;<br>}<br>int choose( int(*fn)(), size_t count, int first,<nobr> <wbr></nobr>...)<br>{<br>&nbsp; &nbsp; va_list arg_ptr;<br>&nbsp; &nbsp; int next;<br>&nbsp; &nbsp; int keep;<br>&nbsp; &nbsp; va_start(arg_ptr,count);<br>&nbsp; &nbsp; keep = va_arg(arg_ptr, int);<br>&nbsp; &nbsp; for(--count; count &gt; 0; --count) {<br>&nbsp; &nbsp; &nbsp; &nbsp; next = va_arg(arg_ptr, int);<br>&nbsp; &nbsp; &nbsp; &nbsp; keep = fn(keep, next);<br>&nbsp; &nbsp; }<br>&nbsp; &nbsp; return keep;<br>}</tt></p></div> </blockquote><p>In retrospect, other than as a learning exercise, this wasn't an ideal test of Inline::C. There's no speed advantage over a pure perl implementation. I ended up with something that seems to be half C and half XS:</p><blockquote><div><p> <tt>use Inline 'C';<br>my @integers = (4, 2, 1, 5, 6, 3);<br> <br>local $\ = "\n";<br>print +choose(\&amp;lessthan, @integers);<br>print +choose(\&amp;grtrthan, @integers);<br> <br>__DATA__<br>__C__<br> <br>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br> <br>int lessthan (int a, int b)<br>{<br>&nbsp; &nbsp; return (a &lt; b) ? a : b;<br>}<br>int grtrthan (int a, int b)<br>{<br>&nbsp; &nbsp; return (a &gt; b) ? a : b;<br>}<br>int choose(CV *fn, int first,<nobr> <wbr></nobr>...)<br>{<br>&nbsp; &nbsp; SV *next_sv;<br>&nbsp; &nbsp; SV *keep_sv;<br>&nbsp; &nbsp; unsigned int count;<br> <br>&nbsp; &nbsp; Inline_Stack_Vars;<br> <br>&nbsp; &nbsp; keep_sv = newSVsv(Inline_Stack_Item(1));<br>&nbsp; &nbsp; for(count = 2; count &lt; Inline_Stack_Items ; ++count)<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; I32 retval;<br>&nbsp; &nbsp; &nbsp; &nbsp; dSP;<br>&nbsp; &nbsp; &nbsp; &nbsp; ENTER;<br>&nbsp; &nbsp; &nbsp; &nbsp; SAVETMPS;<br>&nbsp; &nbsp; &nbsp; &nbsp; next_sv = newSVsv(Inline_Stack_Item(count));<br>&nbsp; &nbsp; &nbsp; &nbsp; PUSHMARK(SP);<br>&nbsp; &nbsp; &nbsp; &nbsp; XPUSHs(sv_2mortal(newSVsv(keep_sv)));<br>&nbsp; &nbsp; &nbsp; &nbsp; XPUSHs(sv_2mortal(next_sv));<br>&nbsp; &nbsp; &nbsp; &nbsp; PUTBACK;<br>&nbsp; &nbsp; &nbsp; &nbsp; retval = call_sv((SV *)fn, G_SCALAR);<br>&nbsp; &nbsp; &nbsp; &nbsp; SPAGAIN;<br>&nbsp; &nbsp; &nbsp; &nbsp; if (retval != 1)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; croak("Big trouble\n");<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; sv_setsv(keep_sv, POPs);<br>&nbsp; &nbsp; &nbsp; &nbsp; FREETMPS;<br>&nbsp; &nbsp; &nbsp; &nbsp; LEAVE;<br>&nbsp; &nbsp; }<br>&nbsp; &nbsp; Inline_Stack_Reset;<br>&nbsp; &nbsp; Inline_Stack_Done;<br>&nbsp; &nbsp; return (int)SvIV(keep_sv);<br>}</tt></p></div> </blockquote> stvn_skuo 2005-02-05T22:00:43+00:00 journal HARNESS_PERL <blockquote><div><p> <tt>[sunnydale:~] skuo% prove -Iblib2/lib t/*.t<br> <br>t/00load.....Perl lib version (v5.8.6) doesn't match executable version (v5.8.0) at<nobr> <wbr></nobr>/usr/local/lib/perl5/5.8.6/darwin/ line 32.<br>Compilation failed in require at<nobr> <wbr></nobr>/usr/local/lib/perl5/5.8.6/Test/ line 18.</tt></p></div> </blockquote><p>It's my fault for having two different versions of perl: 5.8.6 under<nobr> <wbr></nobr>/usr/local/bin and Apple's default perl under<nobr> <wbr></nobr>/usr/bin. </p><p> It turns out that $^X is set to the string 'perl' and trips up my effort at running tests. All's well after setting HARNESS_PERL in my environment to<nobr> <wbr></nobr>/usr/local/bin/perl. </p><p> Perhaps one of the %Config entries should replace $^X inside Test::Harness::Straps (e.g., in &amp;_command)?</p> stvn_skuo 2005-01-28T07:02:44+00:00 journal