mir's Journal http://use.perl.org/~mir/journal/ mir'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:11:23+00:00 pudge pudge@perl.org Technology hourly 1 1970-01-01T00:00+00:00 mir's Journal http://use.perl.org/images/topics/useperl.gif http://use.perl.org/~mir/journal/ DateTime tip http://use.perl.org/~mir/journal/38817?from=rss <p>Note to self: <tt>add</tt> and <tt>subtract</tt> modify the calling object. Use <tt>clone</tt> if you just want to use the result.</p><p>So do not write this:</p><blockquote><div><p> <tt>my $today&nbsp; &nbsp; &nbsp; = DateTime-&gt;now;<br>my $yesterday&nbsp; = $today-&gt;subtract( days =&gt; 1);# changes $today</tt></p></div> </blockquote><p>Instead write this:</p><blockquote><div><p> <tt>my $today&nbsp; &nbsp; &nbsp; = DateTime-&gt;now;<br>my $yesterday&nbsp; = $today-&gt;clone-&gt;subtract( days =&gt; 1); # note the 'clone' call</tt></p></div> </blockquote> mir 2009-04-17T10:06:39+00:00 journal On OS's and user friendliness http://use.perl.org/~mir/journal/36965?from=rss <p>So I just got this USB 3G device, a modem that's supposed to connect me to the World when I am out here on the Tuscan hills. Of course it came with Windows drivers and I don't have a Windows machine, so I plugged it on the Mac and hoped it worked, as usually happens... no dice. You need a driver. Then I tried to install the linux driver that Vodafone gently provides on the (linux) EEE... but I was missing some libraries, and I couldn't get it to run. Grrr... yet an other case of Linux being unfriendly to recent hardware I guessed!</p><p>Then finally "en de'sespoir de cause", I just plugged the device into the darn machine... and low and behold... it Just Worked (tm)! The EEE comes with a piece of software that recognizes my modem, brings up a nice popup and connects me to the rest of the World, from that remote, DSL (and phone!)-deprived area on the Apuan Alps. Yay for Linux! Friendlier than the Mac (and even Windows needs some additional piece of software to be installed I think).</p><p>Sorry Pudge...</p> mir 2008-07-20T17:42:23+00:00 journal Return http://use.perl.org/~mir/journal/36350?from=rss <p>An other reason why subroutine should always end with an explicit <tt>return</tt>.</p><p> XML::Twig has this XML::Parser handler for characters that ends (or rather used to end!) with <tt>$elt-&gt;{pcdata}<nobr> <wbr></nobr>.= $string;</tt>. This is the common case, but it's hidden in the middle of a few if/else's, and it's actually an inlined method call. So it's not obvious what's going on there. But this was what happened when the XML to be parsed included a 4Mb, 60K line, base-64 encoded element: the handler was called 120K times (once for each line, once for each line return). For each of those calls the current content of the element was returned by the handler, and promptly discarded in the bowels of XML::Parser. Except that if you count 120 000 * 4MB/2, that makes nearly 500 GB of memory that needed to be allocated, copied and discarded, for absolutley no good reason at all.</p><p>In the end, adding a <tt>return</tt> at the end of the handler took processing time from 581s to... 2s. It probably improves speed in less specific cases.</p><p>And yes, it is one of Perl Best Practices recommendations (although not for performance reasons). So were was the PBP in 1997 when I wrote the first version of XML::Twig?</p> mir 2008-05-07T16:15:34+00:00 journal