Perl


This comic from xkcd gave me a laugh.

My brother-in-law and sister-in-law sent a t-shirt for Nate that made me smile, “Powered by Perl” Toddler T-Shirt with a camel on it. Must get a picture of him wearing it up on the site.

I’ve been busy with everything else in my life, so I haven’t done much reading. Things have quieted down enough and I’ve picked up:

  • Perl Hacks. Cool little book, full of ideas and tricks you might have known and many more you didn’t. Reminded me of looking over the shoulder of a clever programmer and going, “Aha.” I owe dha a couple of good beers to make up for the review blurb I promised to write but didn’t when I was caught up in closing on a house and moving.
  • Extending and Embedding Perl. I’m working through it now and so far I can say: a) this book was necessary, b) thank you Tim and Simon, and c) XS is never going to be easy but at least it needn’t be a mystery.

Filladapt mode is good but the Perl module Text::Autoformat is better at reflowing text for email. I cobbled together the following elisp to make that easy.

(defun rel-autoformatter (begin end rightmargin)
  "Run Text::Autoformat on region"
  (shell-command-on-region begin end
   (format "perl -MText::Autoformat -e 'autoformat({all=>1,right=>%d})'" rightmargin) t t )
  (message "done."))

(defun rel-autoformat (begin end)
  Text::Autoformat on region, RFC recommended right margin of 72"
  (interactive "r")
  (rel-autoformatter begin end 72))

(defun rel-autoformat-quote (begin end)
  "Text::Autoformat on region, right margin of 60, suitable for quoting replies"
  (interactive "r")
  (rel-autoformatter begin end 60))

(global-set-key (kbd "C-c f f") 'rel-autoformat)
(global-set-key (kbd "C-c f q") 'rel-autoformat-quote)

It might be nice to handle parameters other than right margin- and do it in a cleaner way than explicitly specifying them. I doubt I’ll get around to it since Text::Autoformat usually does the right thing for me with just the margin hint.

At work I have a collection of long-running Perl programs exec-ed by a rc script that have their noise redirected to a single intermingled log. The scripts themselves and the modules they use are littered with carps, warns and print STDERRs depending upon when and by whom they were written. I can differentiate their output (more or less) but I’d like it timestamped for forensic purposes.

My first thought, heaven help me, involving tying filehandles is exampled by this hack:

!/usr/local/bin/perl -w 

use Tie::Handle;
use Carp;
use strict; 

package TimeStamper; 
@ISA = qw(Tie::Handle); 

sub wrap { 
    my $fh = shift; 
    my $fh_name = $fh; 
    $fh_name =~ s/^\*//;
    local *MYFH; 
    open(MYFH, ">&$fh_name") or die("Failed to dupe [$fh_name]: $!"); 
    tie($fh,'TimeStamper',*MYFH); 
} 

sub TIEHANDLE { 
     my ($class,$fh) = @_; 
     my $obj = bless [$fh],$class; 
     return $obj; 
} 

sub PRINT { 
    my $self = shift; 
    my $fh   = $self->[0]; 
    my @t = localtime(); 
    print sprintf("[%4d/%02d/%02d %02d:%02d:%02d] ", 
                  $t[5]+1900,@t[4,3,2,1,0]),@_; 
} 

package main; 

TimeStamper::wrap(*STDERR);
print STDERR "This is timestamped.\n";
warn('This is timestamped.'); 
carp('This is timestamped.');
print "This is not timestamped.\n"; 

Neat. Even half clever. But I’m not sure it’s a good idea.

Next Page »

  • e drugs online
  • the canadien drug store
  • ordering prescription drugs online
  • pharmaceutical drugs online
  • online pharmacudical drugs
  • canada online drug stores
  • online discount pharmacy
  • online pharmacy lowest prices
  • online pharmacy discount
  • online presription drugs
  • online pharmacy prescription drugs
  • drug store on line canada
  • prescription drugs online buying
  • YetAnotherPersonalHomepage is proudly powered by WordPress
    Entries (RSS) and Comments (RSS).
    Original theme design by www.vanillamist.com.