paulm's Journal http://use.perl.org/~paulm/journal/ paulm'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:04+00:00 pudge pudge@perl.org Technology hourly 1 1970-01-01T00:00+00:00 paulm's Journal http://use.perl.org/images/topics/useperl.gif http://use.perl.org/~paulm/journal/ 25 hours in a day http://use.perl.org/~paulm/journal/23190?from=rss <blockquote><div><p> <tt>sub days_between($$) {<br>&nbsp; &nbsp; (str2time($_[1])-str2time($_[0])) / SECONDS_IN_A_DAY;<br>}</tt></p></div> </blockquote><p>Seems obvious enough. Then some results were non-integer. Boiled down to,</p><blockquote><div><p> <tt>$ perl -MDate::Parse -le 'print ((str2time($ARGV[1])-str2time($ARGV[0]))/86400)' 2004-10-31&nbsp; 2004-11-01<br>1.04166666666667<br>$</tt></p></div> </blockquote><p>Why? Ah, Daylight savings!</p> paulm 2005-02-14T16:22:02+00:00 journal Binary reflex http://use.perl.org/~paulm/journal/22652?from=rss <blockquote><div><p>Dave Gould says:<br> &nbsp; &nbsp; 6 OR 7?<br>paulm says:<br> &nbsp; &nbsp; 7<br>Dave Gould says:<br> &nbsp; &nbsp; scuse caps lock<br>paulm says:<br> &nbsp; &nbsp; oh, in that case I don't know</p></div></blockquote> paulm 2005-01-11T04:00:09+00:00 journal Mailman fix_url.py wrapper http://use.perl.org/~paulm/journal/21337?from=rss Mailman has this concept of a URL that's associated with a domain. Unfortunately it's not possible to configure it through the interface, which on vhosted lists is really annoying. There is an impossible-to-remember incantation with an auxilliary script. Tired of looking this up and messing up the invocation here's a wrapper. Yeah, it's in perl.<blockquote><div><p> <tt>#!/usr/bin/perl<br> <br>use strict;<br>use warnings;<br> <br># paulm, 2004-10-14<br># Provide a pleasant interface to mailman's fix_url.py script<br># http://www.python.org/cgi-bin/faqw-mm.py?req=show&amp;file=faq04.029.htp<br> <br>my ($program) = $0 =~ m~.*/(.+)$~;<br>sub usage { die "$program: $program list\@example.com\n@_.\n" }<br>usage("Missing list address")<br>&nbsp; &nbsp; &nbsp; &nbsp; unless @ARGV == 1;<br>my ($local_part, $domain) = split '@', $ARGV[0];<br>usage ("Couldn't parse $ARGV[0] into a list address")<br>&nbsp; &nbsp; &nbsp; &nbsp; unless $local_part and $domain;<br>print "Fixing ${local_part}\@$domain...\n";<br>system qq{/usr/lib/mailman/bin/withlist -l -r fix_url $local_part -u $domain};</tt></p></div> </blockquote> paulm 2004-10-14T10:01:45+00:00 journal Windows NT, VMS? http://use.perl.org/~paulm/journal/19200?from=rss <p>(Lifted from <a href="http://london.pm.org/">London.pm</a>, this thread on <a href="http://london.pm.org/pipermail/london.pm/Week-of-Mon-20040607/027298.html">Windows NT v. VMS</a>).</p><blockquote><div><p> <tt>Je 2004-06-11 00:20:29 +0100, Phil Lanch skribis:<br>&gt; On Wed, Jun 09, 2004 at 02:50:35PM +0100, David Cantrell wrote:<br>&gt; &gt; I would be *much* happier running the bastard child of VMS<br>&gt;<br>&gt; hang on a minute<nobr> <wbr></nobr>... isn't Windows NT the bastard child of VMS?<br> &nbsp; <br>$ perl -pe 's/(.)/chr -1+ord $1/ge'<br>WNT<br>VMS<br>$<br> &nbsp; <br>Apparently.<br> &nbsp; <br>P</tt></p></div> </blockquote><p>Try "IBM" too<nobr> <wbr></nobr><tt>:-)</tt></p> paulm 2004-06-11T15:12:20+00:00 journal Stripping certain requests from log files http://use.perl.org/~paulm/journal/19154?from=rss I have this service that performs a HEAD request on a few sites I run, every few minutes. The problem is that it inflates my page hit count. Being one of those problems that is too annoying to do properly, the following one-liner (line broken for a shot at clarity) came out surprisingly easily,<blockquote><div><p> <tt>for i in www.paulm.com-access.log.*gz; do<br>&nbsp; gunzip $i; f=`echo $i | perl -pe 's/.gz//'`;<br>&nbsp; perl -ni -e 'print unless<nobr> <wbr></nobr>/^ftp.itransact/' $f;<br>&nbsp; gzip $f&amp; echo $f;<br>done</tt></p></div> </blockquote> paulm 2004-06-09T00:32:02+00:00 journal mac2unix http://use.perl.org/~paulm/journal/18983?from=rss <p>A "zero script" hack (-e0) to convert in-place Macs' default line endings of \r to \n.</p><blockquote><div><p> <tt>perl -le0 -015pi mac_file.txt</tt></p></div> </blockquote><p>The order of the -l and -0 is important. -l assigns $\=$/ (output record sep = input record sep) and then the -015 sets input record separator to octal 15, aka dec 13 aka \r. So it's splitting the input on \r and outputting (via -p) with \n.</p><p>(I was puzzled for a while trying to squeeze even more characters out of it by wondering why -l0 was behaving differently to -l -0. -l takes a number too! So the 0 was a number not a command option.)</p><p>Can any more chars be shaved off?</p> paulm 2004-05-28T14:36:35+00:00 journal First post! http://use.perl.org/~paulm/journal/18883?from=rss <p>I've recently really enjoyed reading the journals on use Perl (in particular <a href="/~Matts/journal">Matts's</a> and <a href="/~davorg/journal">davorg's</a> I'm sure I'll discover more!) and combined with a feeling I ought to spend time documenting what I get up to with perlif only so I remember in a week's timeit seemed a natural step to join up.</p><p>If you know me (heck, even if you don't<nobr> <wbr></nobr>:) please do say hi! Any use Perl tips gratefully received too (an overwhelming number of cool-looking doodads here...).</p> paulm 2004-05-22T17:36:17+00:00 journal