Small Mosaic


Categories:

/books
/career
/codinghorrors
/events
/geekstuff
/justdont
/languages
/languages/bash
/linkshot
/magazines
/meta
/misctech
/movies
/nottech
/operatingsystems
/operatingsystems/linux
/operatingsystems/linux/debian
/operatingsystems/solaris
/perl
/presentations
/programming
/python
/ruby
/security
/security/apache
/security/tools
/serversmells
/services
/services/dns
/sites
/specifications
/sysadmin
/testing
/tools
/tools/commandline
/tools/firefox
/tools/gui
/tools/network
/tools/online
/tools/online/greasemonkey
/tools/puppet
/unixdaemon

Archives:

August 20101
July 20101
June 20104
May 20102
April 20101
March 20108
February 20101
January 20102
October 20092
September 200910
August 200910
July 20094
June 20091
April 20093
March 20097
February 20094
January 200917
Full Archives

Tue, 01 Jan 2008

Perl 5.10 - My Favourite Three Features
Since the release of Perl 5.10 (back on 2007/12/18) there have been a fair few articles discussing all the shiny new features - including smart matching, a built-in switch and state variables but my favourite three haven't really received much coverage. So I'll add to the pile of blog posts.

First up is a tiny (from the outside anyway) change that may have the biggest impact of all the new features on my day to day perl - the display of the actual name of uninitialized variables.


# older perls
$ perl584 -we 'print $foo, "\n";'
Use of uninitialized value in print at -e line 1.

# perl 5.10
$ perl510 -we 'print $foo, "\n";'
Use of uninitialized value $foo in print at -e line 1.

From the perspective of someone who has to spend the occasional afternoon reading Apache errorlogs I really like this one.

Now we move on to stackable file tests; something I was surprised perl couldn't do when I first noticed it was missing years ago -


# older perls
...
if (-s $file && -r _ && -x _) {
  print "$file isn't zero length and is +rx\n";
}
...

# perl 5.10
...
if (-s -r -x $file) {
  print "$file isn't zero length and is +rx\n";
}
...

Lastly on my little list is named captures - instead of referencing $1 and $2 etc. you can now assign them names at the point of capture and then pull the values out of a hash at a later time -


# requires 5.10 or above. But not 6.

my %date;
my $sample_date = '20071225';

if ( $sample_date =~ /(?<year>\d{4})(?<month>\d{2})(?<day>\d{2})/ ) {
  %date = %+;
}

say "The year is $date{'year'}";

While none of these are massive attention grabbing additions like the powerful smart matching, switch statement or say (one of those is not like the others ;)) they help make the day-to-day stuff a little more pleasant.

Bonus feature -


my $x;
my $default = 'foo';

$x = 0;
$x ||= $default; 

say "\$x is $x";

$x = 0;
$x //= $default;

say "\$x is $x";

Like this post? - Digg Me! | Add to del.icio.us! | reddit this!

Posted: 2008/01/01 11:59 | /perl | Permanent link to this entry | This entry and same date


New Day, New Year and New job - Well - Two out of Three
As of 6PM yesterday (or midnight - depending on how you interpret my employment contract) my current role is redundant and I'm no longer a member of the working world. It was a mostly good 28 months and I was lucky enough to work with some damn smart people.

This wasn't unexpected. Between the Register articles and a generously lengthened consultation period most of us were pretty sure we'd be on the market again soon. My initial plan was to take a couple of months off (it's been nearly five years since I had more than a week and a half off in a single block) but there is a permie job that sounds very cool and a short term contract I'm interested in (and should hear about today) so I may have to delay the skiving a little longer.

One of the nicer things to come out of this being over is that I can start getting involved in external projects again. I think I'll spend more time this year annoying the people writing some of the projects that should make up my tool chain over the next year or two. I still like Puppet and after a little playing around with Cobbler I quite like it. Especially if the "Debian breed" stuff works. Of course, this means I'll need to learn at least basic Ruby and Python so there goes that extended holiday I was going to take. Unless I lug a pile of books to the beach :)

Now to spend the day lazing around, recover from a late night and enjoy being a drain on society for a whole day. Happy New Year.

Like this post? - Digg Me! | Add to del.icio.us! | reddit this!

Posted: 2008/01/01 11:01 | /career | Permanent link to this entry | This entry and same date


books career codinghorrors events geekstuff justdont magazines meta misctech movies nottech operatingsystems/linux operatingsystems/linux/debian operatingsystems/solaris perl programming python ruby security security/apache security/tools serversmells services/dns sites sysadmin testing tools tools/commandline tools/firefox tools/gui tools/network tools/online tools/online/greasemonkey tools/puppet unixdaemon

Copyright © 2000-2010 Dean Wilson XML feed logo