polettix's Journal http://use.perl.org/~polettix/journal/ polettix'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:32:35+00:00 pudge pudge@perl.org Technology hourly 1 1970-01-01T00:00+00:00 polettix's Journal http://use.perl.org/images/topics/useperl.gif http://use.perl.org/~polettix/journal/ playing with rakudo http://use.perl.org/~polettix/journal/39537?from=rss <p>These days I've played a bit with <a href="http://rakudo.org/">rakudo</a> (should I say Rakudo? I actually played with the program...) and I really enjoyed it.</p><p>I focused on implementing short examples in the <a href="http://github.com/perl6/perl6-examples/tree">perl6-examples</a>, in particular related to <a href="http://projecteuler.net/">Project Euler</a>. It allows me to use the "everyday" Perl 6 waiting to exploit more advanced features, which is good. It's quite easy to have access to the Github repository, as a matter of fact it boils down to joining #perl6 in freenode and ask.</p><p>Performance is really poor so far, some scripts in Perl 5 that run in some 3 seconds take ages in Perl 6. Anyway, at the moment it's not really the point - not for me, at least - so the level of fun is high. I must admit that it's easy to get used to the syntax changes, like the one for "for.</p><p>I was a bit scared in being hit by a couple of lacks/bugs while doing quite basic stuff. One resulted in a bug report, another one was due to a known bug. Was I particularly lucky? I hope so.</p> polettix 2009-08-26T15:54:19+00:00 journal Accessing Amazon S3 from the command line http://use.perl.org/~polettix/journal/37319?from=rss <p>I started playing with <a href="http://www.amazon.com/gp/browse.html?node=16427261">Amazon Simple Storage Service</a> and <a href="http://use.perl.org/~acme/">acme</a>'s <a href="http://search.cpan.org/dist/Net-Amazon-S3/">Net::Amazon::S3</a>, finding both quite useful and easy to use.</p><p>The obvious next step has been re-inventing the wheel. Well, sort-of, because the type of wheel I had in mind wasn't anywhere I was able to look for. In particular, I was looking for some "operating-system command" a-la git that was able to support subcommands for common operations.</p><p>So, I concentrated on two sets of commands: the "pure" ones, that focus on Amazon's way of seeing data, and the "filesystem" ones, that support thinking S3 stuff as files with a Unix-like path.</p><p>Among the first group you can find the basic S3 functions like add, remove etc. The second group has more "convenient" commands like ls, cp, rm and mv, that try to do the right thing in the spirit of the corresponding Unix commands (e.g. cp can both send or get data, depending on the order of the parameters). I find this useful because the metaphor is somewhat "hardcoded" in me after years of using those commands.</p><p>If you're interested or just want to find something to start a flamewar, you can find it at <a href="http://repo.or.cz/w/s3.git">http://repo.or.cz/w/s3.git</a>. Enjoy!</p><p>Update: thanks to grink's tip below, I found <a href="http://search.cpan.org/dist/Term-ShellUI/">Term::ShellUI</a> that allowed me to add an interactive shell to call all of the commands, with on-line help! I love CPAN.</p> polettix 2008-08-31T17:49:21+00:00 journal My take on system administration: deployable http://use.perl.org/~polettix/journal/37142?from=rss <p>Some time ago I had to take care of the configuration of a bunch of Linux servers (more or less fifty of them so far), most of which have identical configuration apart some bits. These bits are typically the hostname, the IP address ecc., but also more specific and application-related info that I can't talk about.</p><p>I started using a lot of ssh and quickly realised that I had to make stuff as automatic as possible. This is probably what led me to the wheel-reinventer land once again (this was also the reason why I developed Template::Perlish, by the way). My idea of an ideal workflow for this type of activities is simple:</p><p>* figure out what has to be done in some test environment</p><p>* collect all the needed bits that need to be deployed and possibly executed in each server</p><p>* put these bits in place and execute what's needed.</p><p>While there's little to automatise for the first bullet, the second and the third have definitively space for letting me do more interesting things.</p><p>The second bullet boiled down to this: most of the times, I either had to deploy some new configuration files that were pretty the same for all the servers (or groups of them), or I had to execute some script in the target machine, where these scripts needed also some supporting data files.</p><p>What I wanted, in order to ease the third bullet, was a way to produce a single, self-contained script that was able to carry all the needed bits and do all the magic once executed. In other words, I needed some executable archive, which had to be able to hold all the files, figure out where they had to be installed depending on their "role", and execute all the "deployment" scripts. This led to a script - deployable - that is some specialised archiver that takes some lists of files/directories and produces a single script that is capable of all the magic in the remote server.</p><p>The produced script works with the least requirements, due to the fact that I wanted to change the target environment as little as possible. Thus, the underlying archiver of choice has been tar, and the remotely distributed script is capable of carrying Archive::Tar inside if it's not installed in the target machine; alternatively, it can rely upon system tar, if present.</p><p>The last part, i.e. the actual deployment, can be handled by another script - deploy. It basically does two things with a "deploy-script" produced by deployable: sftp-s it into each of the targets, then ssh-s and executes it. By default it works into a temporary directory that is created, from time to time, inside a base camp in<nobr> <wbr></nobr>/tmp/our-deploy, but it's all configurable.</p><p>If you want to take a look, or just comment harshly on how this is reinventing multiple wheels, feel free to do! You can find a git repository with the needed tools at <a href="http://repo.or.cz/w/deployable.git">http://repo.or.cz/w/deployable.git</a> (you can take a plain old tarball going to <a href="http://repo.or.cz/w/deployable.git?a=shortlog">http://repo.or.cz/w/deployable.git?a=shortlog</a> and clicking on the first "snapshot" link you find in the list). Enjoy!</p> polettix 2008-08-10T01:54:32+00:00 journal Variable holding a reference to itself http://use.perl.org/~polettix/journal/36856?from=rss <p>Today I did something that's totally insane:</p><blockquote><div><p> <tt>&nbsp; &nbsp;$image = \$image unless ref $image;</tt></p></div> </blockquote><p>The intent was normalising the input to a sub, which can be either the image or a reference to the image's data. My goal was to always have a reference.</p><p>After some debugging, it became clear that the "hold a reference to yourself" is plain wrong. I was relying on some obscure reasoning inside my brain, about the fact that taking that reference would magically "detach" the variable container from $image, just to take a reference to the container and put it into a new container in $image.</p><p>Luckily, sometimes Perl just refuses to DWIM, and with good reasons.</p> polettix 2008-07-05T15:12:03+00:00 journal Sometimes the solution is under your nose http://use.perl.org/~polettix/journal/36853?from=rss <p>I think it's hard not to admit that Image::Magick documentation simply sucks. IMHO it's a wonderful module, I simply hate the docs.</p><p>One thing that I've been eager to do for a long time has been getting image data in memory instead of writing them to a file. I tried in-memory filehandles, but with no luck. There's always been an interesting ImageToBlob method, but it was a bit short-ranged... at least I believed. Reading the docs, it seemed that it was able to spit data out only in the original format... whatever it means for some dynamically generated image.</p><p>Today I had the pleasure to discover that this isn't actually the case. You can use that method to get image data in memory and in any format you want... just pass the magick parameter with the indication of the format:</p><blockquote><div><p> <tt>&nbsp; &nbsp;my $png_data = $image-&gt;ImageToBlob(magick =&gt; 'png');</tt></p></div> </blockquote><p>I wish I knew this a long time ago.</p> polettix 2008-07-04T22:41:34+00:00 journal When tests unveil bugs - more or less... http://use.perl.org/~polettix/journal/36788?from=rss <p>This has been a nightmare... more or less.</p><p>It's all dakkar's fault. He wrote an <a href="http://www.perl.it/documenti/articoli/2007/09/gtk2-perl-e-dra.html">interesting article in perl.it</a> (in Italian, sorry!) about using the Gtk2 module, how easy it was to build up an application, etc. and so I was heading to my shell in no time.</p><p>I use debian etch, which comes with a lot of packages for Perl modules, but I like to separate system stuff from what I use, so I stick to a custom version of perl. There I was, in front of my cpan shell, but the installation process failed miserably: Glib had issues!</p><p>Ok, on to the build directory, then, to see the offending test. There it is! t/64bit.t chokes! There seem to be a problem invoking Glib::ParamSpec::int64, but the problem immediately seems to be somewhere in the underlying library because there are some complains from the library itself in stderr. In particular, when calling the function, it seemed that this assertion failed:</p><blockquote><div><p> <tt>&nbsp; &nbsp;MIN_INT64 &lt; 0 &lt; MAX_INT64</tt></p></div> </blockquote><p>I have to admit that it took me a while to understand that the problem was in the glib library. How could this possibly be? So I wasted some time navigating through XS code (very little time), doing some hacks with fprintf/stderr in the generated C code (some more time) and finally it seemed that I could restrict the error to the underlying call to g_param_spec_int64().</p><p>It was time for my first false route, so I happily took it. I concocted what I thought to be a minimal example to compile, just to see that it crashed immediately. In the beginning, I was looking for the actual target to blame, so I tried to change compiler (using gcc-3.3 and gcc-3.4) and a couple of voodoo rites found in the Internet, but no luck. I finally came into another example that was sufficiently minimal for my eyes to eventually catch that g_type_init() was needed *before* calling the other function. At least I was back in the correct route!</p><p>In the meantime, I also tried to download the latest version of the glib library, compiled it and installed somewhere useful. I then forced a compilation/link against that library, and the test went fine! Ok, then... the library seems the one to blame.</p><p>So I finally had something useful to at least prove that the function wasn't working, but I had to quickly change my mind, because the following test program worked like a charm:</p><blockquote><div><p> <tt>shell$ cat prova.c<br>#include &lt;stdio.h&gt;<br>#include &lt;glib.h&gt;<br>#include &lt;glib-object.h&gt;<br> &nbsp; <br>int main (int argc, char *argv[]) {<br>&nbsp; &nbsp;GParamSpec *pspec;<br> &nbsp; <br>&nbsp; &nbsp;g_type_init();<br> &nbsp; <br>&nbsp; &nbsp;printf("starting, first goes well\n");<br>&nbsp; &nbsp;pspec = g_param_spec_int64("int64", "Int", "Bah!",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;G_MININT64, G_MAXINT64, 0,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;G_PARAM_READWRITE);<br> &nbsp; <br>&nbsp; &nbsp;printf("putting min equal to max, and default outside\n");<br>&nbsp; &nbsp;pspec = g_param_spec_int64("int64", "Int", "Bah!",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;G_MAXINT64, G_MAXINT64, 0,<nobr> <wbr></nobr>/* min set to G_MAXINT64 */<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;G_PARAM_READWRITE);<br> &nbsp; <br>&nbsp; &nbsp;return 0;<br>}<br>shell$ gcc $(pkg-config --cflags --libs gobject-2.0) prova.c -o prova<br>shell$<nobr> <wbr></nobr>./prova<br>starting, first goes well<br>putting min equal to max, and default outside<br> &nbsp; <br>(process:9229): GLib-GObject-CRITICAL **: g_param_spec_int64: assertion `default_value &gt;= minimum &amp;&amp; default_value &lt;= maximum' failed</tt></p></div> </blockquote><p>I was starting to get nervous! The function seemed to work fine... so it was time to go back in the XS/C code and try to figure out what was going on. After some munging, I discovered that parameter grabbing was not working as expected; the following call in GParamSpec.c:</p><blockquote><div><p> <tt>gint64&nbsp; &nbsp;minimum = SvGInt64 (ST(5));</tt></p></div> </blockquote><p>was generating a *positive* value even when provided a *negative* one. On to SvGInt64 in GType.c, then:</p><blockquote><div><p> <tt>gint64<br>SvGInt64 (SV *sv)<br>{<br>#ifdef USE_64_BIT_ALL<br>&nbsp; &nbsp;return SvIV (sv);<br>#else<br>&nbsp; &nbsp;return PORTABLE_STRTOLL (SvPV_nolen (sv), NULL, 10);<br>#endif<br>}</tt></p></div> </blockquote><p>OMG, <code>PORTABLE_STRTOLL</code>, a macro! After a bit of discussion with the Makefile I grab the (huge) command line to compile the GType.c file, and adding the <code>-E</code> switch lets me access the code *after* macro expansion. The bottom line is that <code>PORTABLE_STRTOLL</code> simply resolves to a call to g_ascii_strtoll(). Ok, another step in the (hopefully) right direction.</p><p>First a bit of googling to try to find out if there had been a known issue. This resolved to be a waste of time, I had better go and compare the two implementations in the original version I had in my system and the latest version. In fact, it seems that someone already discovered that there was a bug in that function, and the solution was there in the new code.</p><p>What to do, then? The first thing that came to mind was sending a bug report to debian, because the library in etch is broken! I used git to produce the patch (and this lead to another thread of discussion about the diff format generated by git-format-patch, but this is another story!) and sent it along to the debian maintainers, hoping not to have done any error in the process. But the answer didn't come in a handful of hours, so I had to think something more. (Yes, I'm that impatient, maybe this is why I stick to Perl).</p><p>I had two alternatives: either force the install (who will be using that 64 bit stuff anyway?!?), or upgrade the library by myself. I found an interesting article about <a href="http://www.ducea.com/2008/03/06/howto-recompile-debian-packages">recompiling a debian package</a>, so I immediately got to work. No, things didn't go smoothly, because the debuild program (or whatever sub-program it called) insisted in complaining that the modified tarball with my patch wasn't the same as the original (guess why?!?). After a bit of tweaking I managed to make it generate a new package, anyway.</p><p>Prior to installing it I made a checkpoint to the virtual machine I'm running Linux in, just to be on the safe side. Having such a facility is sooo great, you can go back at once if things go wrong. Then I installed the package and voil&#224;! The Glib module compiled, at last!</p><p>Anyway, I now ask myself: how come that the debian package for Perl's Glib didn't have the same problem?!?</p> polettix 2008-06-26T15:24:39+00:00 journal Falled into the trap: Template::Perlish http://use.perl.org/~polettix/journal/36096?from=rss <p>So I finally falled into the trap - I wrote a templating system: Template::Perlish. A very basic one, just giving you means to put some variables here and there, and use Perl for all control structures.</p><p>The thing I love about it is that I needed it. It vaguely resembles TT2 - at least in the way you put the variables. This let me take a bunch of TT2 templates and more or less keep them switching to the new templating system. The other thing I love is that all what's more complicated than a simple variable is just plain Perl - and I love Perl.</p><p>Why, then? I'm working on an automatic deployment system, to build up a server image that can be deployed and auto-configures all those tiny bits like network configurations and stuff like this, based on some master configuration file. At first I developed it in TT2, and executed it on my machine, but then each new server needed my intervention after server image deploy. This should let me avoid this.</p><p>So, I needed something that I could carry very easily anywhere Perl 5.8 was present.</p><p>One thing that makes me proud is that for the new 1.1 release there are a few features added and a few removed. Like accessors for the three member variables: actually not needed due to the extreme simplicity of the module. I'm still thinking if an "include" feature is needed, but I won't probably be adding it until it's evident that this is a lacking feature. It's like a gym where I can practice some refrain to feeping creaturism - ehr, creeping featurism.</p> polettix 2008-04-08T00:23:14+00:00 journal sort SUBNAME LIST is sick http://use.perl.org/~polettix/journal/35360?from=rss <p>I was bite by this:</p><blockquote><div><p> <tt>#!/usr/bin/env perl<br>use strict;<br>use warnings;<br> &nbsp; <br>my @stuff = sort returns_list('whatever');<br>print "stuff: [@stuff]\n";<br> &nbsp; <br>@stuff = returns_list('again');<br>@stuff = sort @stuff;<br>print "stuff: [@stuff]\n";<br> &nbsp; <br>sub returns_list {<br>&nbsp; &nbsp;return qw( howdy all of you );<br>}<br> &nbsp; <br>__END__<br> &nbsp; <br>poletti@PolettiX:tmp$<nobr> <wbr></nobr>/opt/perl-5.8.8/bin/perl bug.pl<br>stuff: [whatever]<br>stuff: [all howdy of you]<br>poletti@PolettiX:tmp$<nobr> <wbr></nobr>/opt/perl-5.10.0/bin/perl bug.pl<br>stuff: [whatever]<br>stuff: [all howdy of you]</tt></p></div> </blockquote><p>which is regarded as (thanks dakkar):</p><blockquote><div><p> <tt>$ perl -MO=Deparse sort_bug.pl<br>use warnings;<br>use strict 'refs';<br>my(@stuff) = (sort returns_list 'whatever');<br>print "stuff: [@stuff]\n";<br>@stuff = returns_list('again');<br>@stuff = sort&nbsp; @stuff;<br>print "stuff: [@stuff]\n";<br>sub returns_list {<br>&nbsp; &nbsp; use warnings;<br>&nbsp; &nbsp; use strict 'refs';<br>&nbsp; &nbsp; return 'howdy', 'all', 'of', 'you';<br>}</tt></p></div> </blockquote><p>dakkar also reminded me that this was the only way to support what then became <code>sort BLOCK LIST</code>.</p><p>This is just sick.</p> polettix 2008-01-11T10:59:22+00:00 journal OO and "private" methods http://use.perl.org/~polettix/journal/35312?from=rss <p>I was writing a couple OO modules and I was struck by a thought about "private" methods. In that quite private context that's my mind, I'm basically thinking of "private" methods as those methods that you don't explicitly support for external usage, but that come handy in your own implementation of a class, mostly for refactoring stuff. So I'm not meaning it in the mainstream OO tongue (like enforcing its usability only within the class), but more on the "intended audience" -- which seems quite in line with Perl's approach.</p><p>What made me scared all at once was realising that some derived class could actually override that private method, without explicitly knowing about it! For example, if I have factored out some logic into some "private" method:</p><blockquote><div><p> <tt>sub _get {<br>&nbsp; &nbsp;# do stuff<br>}</tt></p></div> </blockquote><p>using such a simple sub name, it could well be that someone using my class can implement its own "private" sub <code>_get</code>, and blow it all!</p><p>Thinking a bit about this, the solution is obvious. If I want methods that can't be overridden, just stop calling them "methods", and call them just "subs". Which means that instead of:</p><blockquote><div><p> <tt>my $stuff = $self-&gt;_get(@whatever);</tt></p></div> </blockquote><p>I have to use:</p><blockquote><div><p> <tt>my $stuff = _get($self, @whatever);</tt></p></div> </blockquote><p>turning OO magic off. Something to remember in the future.</p> polettix 2008-01-07T01:48:27+00:00 journal Roma.pm wishes best luck to dada http://use.perl.org/~polettix/journal/35296?from=rss <p>Yesterday night Roma.pm met to wish best luck to dada and wife, for their imminent Austrian adventure. For such a big happening, we also had the honour to host larsen and dakkar from Firenze.pm and Pisa.pm - they're always a pleasure to meet in person. While Austria is not that distant, I'll surely miss my lunches with dada.</p><p>Roma.pm has never been too much active, at least in organising technical meetings. OTOH I've really enjoyed many mailing list threads up to now. Luckly, the emigrants (can) continue to partecipate in the mailing list. The sad part being that plural.</p><p>In the last year, dada is the second person leaving Roma for another country, following malattia (which went to Japan). And others went away in the past, like oha which I never met in person. While it's great that they're going to such wonderful places to make their lives better, it's sad for me to think that they've not found what they deserve here, and that I can't enjoy their company. They're really smart people and taught me a lot.</p><p>But this is probably a general trend here in Italy, in particular centre-south Italy. Whatever the goverments (*any* government) say, opinions abroad are quite right IMHO.</p><p>Anyway, don't think we completely disappeared! We'll continue to have dinners, talk like ner*COUGH*geeks and enjoy life!</p> polettix 2008-01-05T16:06:32+00:00 journal See you soon dada! http://use.perl.org/~polettix/journal/35279?from=rss Tomorrow <a href="http://www.perlmonks.org/?node=dada">dada</a> is leaving Roma for his new job adventure in Wien. If by chance any of you happens to be in Roma, we're going to have dinner together: write me (flavio at polettix dot it) if you're interested. polettix 2008-01-03T20:14:34+00:00 journal MMS::Parser http://use.perl.org/~polettix/journal/34904?from=rss <p>Some days ago I finally uploaded to CPAN a first release of MMS::Parser, which is wandering in my PC since a long time. It's a library to parse binary MMS messages, for the moment supporting the two main "scenarios" regarding the outgoing message and the incoming one.</p><p>While it is more or less usable (my colleagues are using it in a demo application somewhere) it really lacks documentation, and test coverage is not complete.</p><p>Moreover, I'm planning to produce a real object hierarchy instead of a simple HoH, so I'll probably take a look somewhere around MIME::*.</p> polettix 2007-11-16T00:35:13+00:00 journal ImageMagick 6.3.6 http://use.perl.org/~polettix/journal/34881?from=rss <p>I upgraded to ImageMagick 6.3.6 last night and the nightmare of such things popped out: my scripts terminated suddenly with a "Segmentation fault". Ouch. On the other hand, the test suite for the Perl modules sort-of-worked, with some issues on a test file. So, it couldn't be *that* broken.</p><p>It ended up that it was a "coders" directory put somewhere, and in particular the ".so" library files that were in it. I don't really know anything about autoconf and libtool, but the most evident thing was that in the compiled directory there were two libraries for each file, one ending in ".so" and the other ending in ".soT", which was the one that got installed (and that caused the problem). And yes, the *dirty* hack to copy the original ".so" files over the broken ones worked.</p><p>I suspect that my compiling toolchain is a little dated... time to upgrade, I fear.</p> polettix 2007-11-12T08:47:23+00:00 journal TheDamian vs. domm arm fight http://use.perl.org/~polettix/journal/34323?from=rss <p>After having completely enjoyed YAPC::EU 2007 (my first one!), I'm going through my photos and videos and so far I've uploaded two videos of the TheDamian-domm arm fight on YouTube. The first one is <a href="http://www.youtube.com/watch?v=6w1JUteErrU">from the beginning to some time near the end</a>.</p><p>I then realised that the quality was quite poor (due to digital zoom during recording), so I stopped, zoomed (optically) and was lucky enough to record <a href="http://www.youtube.com/watch?v=w214S29OTcs">the very end</a>.</p><p>Enjoy!</p> polettix 2007-09-03T09:37:23+00:00 journal Roma.pm wishes good holidays http://use.perl.org/~polettix/journal/33966?from=rss <p>Yesterday we got together, at last! Happy partecipants were (in no particular order) Aldo, Chris, Marco, Stefano, Emanuele and I. Ok, there was a particular order, but nevermind.</p><p>We usually try to stay far away from Perl in these Mongers meetings, but we always fall down. Yesterday we had an interesting conversation about 'use vars' and 'our', with Emanuele being an advocate for 'our' (and citing the docs for 'use vars' being deprecated) and Aldo and I saying that 'our' was out of the 1337 clubs. Well, 'saying' is not completely true: we had that we-know-it-all-baby look and voice tone, but Emanuele is no baby at all and quickly disarmed us with the simplest of questions ("where did you read this? gimme references, and good ones!") and citing passes from the documentation at heart.</p><p>The bottom line is that neither Aldo nor I found the references we were thinking about, apart from a couple of rants by tilly on Perl Monks and a tutorial from Ovid. But I can swear that it was all Weisbeer's fault.</p><p>Marco was amazed by the simplicity of the Perl object system, which we tried to explain briefly. Thinking about it, I must admit that building an entire object system on more or less two user-tweakable things (bless and @ISA) is really *great*. Whatever the object system for Perl 6 will be<nobr> <wbr></nobr>:)</p><p>After what we can consider my first truly technical dinner in Perl, we found that we were hostage in the restaurant, but fortunately we had eaten enough to gain the possibility to get out (you have to spend a minimal amount of money in that place, it seems).</p> polettix 2007-08-02T17:52:28+00:00 journal One question about Perl 6 http://use.perl.org/~polettix/journal/33039?from=rss Last night (at least here in Italy) I asked a question about Perl 6, I hope TimToady won't sue me for reporting it here<nobr> <wbr></nobr>:) (Note: I eliminated a comment by Limbic~Region from the original log, that referred to another thread of discussion).<blockquote><div><p> <tt>apr 19 01:22:02 &lt;polettix&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;disclaimer&gt;I'm not asking for dates!&lt;/disclaimer&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;what percentage of Perl 6 specs definition do you<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;think we (well... you) are at?<br>apr 19 01:22:56 &lt;TimToady&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;we're well past the first 80% and well into the<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;second 80%.&nbsp;<nobr> <wbr></nobr>:)<br>apr 19 01:23:52 &lt;polettix&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nice answer, and I suspect it also represents the<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;reality quite well<nobr> <wbr></nobr>:)<br>apr 19 01:23:56 &lt;TimToady&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;in other words, most of the important stuff is<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;done, and much of what remains is a protracted<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;negotiation between the current design and the<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;implementors<br>apr 19 01:24:26 &lt;TimToady&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;with assorted input from educators and users<br>apr 19 01:25:29 &lt;TimToady&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;plus a gentle undercurrent of "keep everything<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else the same as Perl 5"</tt></p></div> </blockquote> polettix 2007-04-20T00:49:15+00:00 journal Origami camel, at last! http://use.perl.org/~polettix/journal/32858?from=rss <p>At last I received <a href="http://isbn.nu/0486265870">Origami Sculptures</a> by John Montroll, containing a diagram for a beautiful camel (it contains both the double-humped bactrian camel and the single-hump dromedary). Well, my camel is not so beautiful, but <a href="http://img128.imageshack.us/img128/1245/dscn2032ik9.jpg">here</a> it is!</p><p> (According to <a href="http://www.oreillynet.com/pub/a/oreilly/perl/usage/">this</a>, it seems that I have to state that the use of the Camel in association with Perl is trademark of O'Reilly, and that I have to link back to <a href="http://www.perl.com/">perl.com</a>. If you think that I'd so something more please let me know, I might have misunderstood the terms linked above for non-commercial usage).</p> polettix 2007-03-31T16:16:35+00:00 journal IPC::Open3 quirks http://use.perl.org/~polettix/journal/32851?from=rss <p>I sometimes record some modules as possible "future save-the-day solutions" when I read about them, mostly on <a href="http://www.perlmonks.org/">Perl Monks</a>. One of these modules is <a href="http://search.cpan.org/~nwclark/perl-5.8.8/lib/IPC/Open3.pm">IPC::Open3</a>, but I'd take more care in ensuring these safe nets.</p><p>IPC::Open3 is useful when you want complete input/output control on a spawned process, i.e. when you have to control its STDIN, STDOUT and STDERR as well. The interface is quite straightforward:</p><blockquote><div><p> <tt>$pid = open3(\*WTRFH, \*RDRFH, \*ERRFH,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'some cmd and args', 'optarg',<nobr> <wbr></nobr>...);<br> <br>my($wtr, $rdr, $err);<br>$pid = open3($wtr, $rdr, $err,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'some cmd and args', 'optarg',<nobr> <wbr></nobr>...);</tt></p></div> </blockquote><p>One thing that the docs state quite clearly is the following:</p><blockquote><div><p>If ERRFH is false, or the same file descriptor as RDRFH, then STDOUT and STDERR of the child are on the same filehandle.</p></div> </blockquote><p>It's easy (at least for me) to overlook this, and you can imagine my surprise discovering that all the STDERR of the spawned process goes straight to STDOUT, and the filehandle for $err is undefined. What's not so easy is to discover <b>how</b> one can address this issue. IMHO, the "Do What I Mean" mantra has been spectacularly betrayed here, where I would expect a brand new handle to be created for me. Just like $wtr and $rdr, you know. Just like the filehandle in open().</p><p>Thanks to <a href="http://www.perlmonks.org/?node_id=150748">this thread</a>, I discovered one solution to the problem: gensym. Here's a working snippet, at last:</p><blockquote><div><p> <tt>#!/usr/bin/perl<br># see also http://www.perlmonks.org/?node_id=150748<br> <br>use strict;<br>use warnings;<br>use IPC::Open3 qw( open3 );<br>use Symbol;&nbsp; &nbsp; # provides gensym<br> <br>my ($in, $out, $err);<br>$err = gensym();&nbsp; # Aha! This was what I was after<br>my $pid = open3($in, $out, $err, '/bin/ls', '/path/to/inexistent', '/tmp')<br>&nbsp; or die "open3(): $!";<br> <br>my @emsg = &lt;$err&gt;; # The error comes from here<br>print {*STDOUT} "process STDERR: @emsg\n" if @emsg;<br> <br>my @omsg = &lt;$out&gt;; # Output for existing stuff<br>print {*STDOUT} "process STDOUT @omsg\n" if @omsg;<br> <br>__END__<br> <br>poletti@PolettiX:~/sviluppo/perl$ perl open3-gensym.pl<br>process STDERR:<nobr> <wbr></nobr>/bin/ls:<nobr> <wbr></nobr>/path/to/inexistent: No such file or directory<br> <br>process STDOUT<nobr> <wbr></nobr>/tmp:<br> prova<br> v206821<br> v206828<br> v274678<br> v279868<br> v283182</tt></p></div> </blockquote><p>Something to remember well for the future...</p> polettix 2007-03-30T23:23:45+00:00 journal project's todo with hiveminder http://use.perl.org/~polettix/journal/32834?from=rss Using <a href="http://hiveminder.com/">Hiveminder</a>'s <a href="http://hiveminder.com/static/tools/cli/todo.pl">command line</a> interface (described <a href="http://bestpractical.typepad.com/worst_impractical/2006/09/todopl_or_how_i.html">here</a>), I put together this simple wrapper shell script:<blockquote><div><p> <tt>#!/bin/bash<br>if [ -z "$1" ] ; then<br>&nbsp; &nbsp;todo.pl --tag project-name list<br>else<br>&nbsp; &nbsp;todo.pl --tag project-name "$@"<br>fi</tt></p></div> </blockquote><p>that I install in the "bin" directory of my new projects. In this way, I'm able to track to-dos via this simple interface within the project ("project-name" above in the script is "rubrica" in the example below):</p><blockquote><div><p> <tt># List, by default<br>pinco@pallo<nobr> <wbr></nobr>/path/to/rubrica$ bin/todo<br>1H27 aggiungere le foto nella lista globale [rubrica]<br>1H35 verificare gli errori nella gestione delle pagine [rubrica]<br> <br># Todo set to "done"<br>pinco@pallo<nobr> <wbr></nobr>/path/to/rubrica$ bin/todo done 1h27<br>Finished task<br> <br># Task addition<br>pinco@pallo<nobr> <wbr></nobr>/path/to/rubrica$ bin/todo add 'verificare ordinamento per cognome'<br>Created task<br> <br># List (updated)<br>pinco@pallo<nobr> <wbr></nobr>/path/to/rubrica$ bin/todo<br>1H35 verificare gli errori nella gestione delle pagine [rubrica]<br>1KH7 verificare ordinamento per cognome [rubrica]</tt></p></div> </blockquote><p> <b>Update</b>: I also added a little function into my<nobr> <wbr></nobr>.bashrc to automatically call the bin/todo script if available, or to call todo.pl if not.</p><blockquote><div><p> <tt>function todo () {<br>&nbsp; &nbsp; if [ -e 'bin/todo' ]; then<br>&nbsp; &nbsp; &nbsp; &nbsp; bin/todo "$@";<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; todo.pl "$@";<br>&nbsp; &nbsp; fi<br>}</tt></p></div> </blockquote><p>In this way, when I'm inside the directory of one of my projects that have a bin/todo, this is what gets called. Otherwise, it is a simple proxy for the straight todo.pl script.</p><p> <b>Update</b>: I ended up getting rid of the script and adding a simple<nobr> <wbr></nobr><code>.todo-tags</code> file where I need it. I also substitued the shell function with the following script:</p><blockquote><div><p> <tt>#!/bin/bash<br> <br>if [ -e '.todo-tags' ] ; then<br>&nbsp; &nbsp;taglist=$(cat<nobr> <wbr></nobr>.todo-tags | sed 's/^/--tag<nobr> <wbr></nobr>/')<br>fi<br>echo todo.pl $taglist "$@"<br>todo.pl $taglist "$@"</tt></p></div> </blockquote><p>In the<nobr> <wbr></nobr><code>.todo-tags</code> all tags are on different lines and cannot have spaces, of course, but this works for me 100% of times.</p> polettix 2007-03-29T13:52:39+00:00 journal The Sieve of Eratosthenes http://use.perl.org/~polettix/journal/32452?from=rss Translating <a href="http://www.onlamp.com/pub/a/python/excerpt/pythonckbk_chap1/index1.html?page=last">a python function</a> for a sieve of eratosthenes (a way to detect prime numbers), I've come up with this:<blockquote><div><p> <tt>sub eratosthenes {<br>&nbsp; &nbsp;my %D;<br>&nbsp; &nbsp;my $q = 2;<br>&nbsp; &nbsp;return sub {<br>&nbsp; &nbsp; &nbsp; while (defined(my $p = delete $D{$q})) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;my $x = $p + $q;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$x += $p while exists $D{$x};<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$D{$x} = $p;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;++$q;<br>&nbsp; &nbsp; &nbsp; } ## end while (defined(my $p = delete...<br>&nbsp; &nbsp; &nbsp; $D{$q * $q} = $q;<br>&nbsp; &nbsp; &nbsp; return $q++;<br>&nbsp; &nbsp;};<br>} ## end sub eratosthenes</tt></p></div> </blockquote><p>It's nice, even if it tends to blow for increasing values (due to memory requirements).</p> polettix 2007-02-20T23:43:46+00:00 journal I'd like to RTFM... http://use.perl.org/~polettix/journal/32443?from=rss <p>... but it seems that use.perl doesn't like to have a FM... Asked for help but my "Ask Use Perl" question was rejected... Maybe it's true that we're like "guniea pigs" (<a href="http://use.perl.org/faq.shtml">FAQ</a>). </p><p>I've become quite addicted with <a href="http://projecteuler.net/">projecteuler.net</a> thanks to blazar (I'd link him if I only knew how to do it without putting a long ugly href<nobr> <wbr></nobr>:) Yesterday I solved one problem using bigint, only to find that I didn't need it and that my code could run in 20 seconds instead of more than 2 hours.</p> polettix 2007-02-20T00:17:30+00:00 journal The New Trolls http://use.perl.org/~polettix/journal/32400?from=rss I am amazed when I see that some people always find new and original ways to be a troll (could we call these ones <a href="http://en.wikipedia.org/wiki/New_Trolls">New Trolls</a>?). This two-days old <a href="http://www.perlmonks.org/?node_id=599759">monk</a> gifted me with sincere laughs <a href="http://www.perlmonks.org/?node_id=599766">here</a>, <a href="http://www.perlmonks.org/?node_id=599773">here</a> and <a href="http://www.perlmonks.org/?node_id=599940">here</a>. Useful when you're a bit sad... polettix 2007-02-14T14:20:04+00:00 journal