Cookie Notice

As far as I know, and as far as I remember, nothing in this page does anything with Cookies.

2010/06/01

Absolutely Awesome Perl Modules: Cwd

It's the libraries that make a language. It's nice to have cool ways to do loops and such, but if the tool does the task you need it to do, that's what pays the bills.

This is one I've found very useful. Cwd gives you your current working directory with getcwd and it also takes a relative path or and gives you the absolute path, with abs_path.

This is a small script that sends an image path to gconftool to set as the background image. I call it set_background.pl. gconftool is a stickler for absolute paths ('/home/user/Pictures/foo.png', for example), and I could either hack something up to make absolute paths, or I can just use Cwd 'abs_path' ;

#!/usr/bin/perl

use 5.010 ;
use strict ;
use warnings ;
use Cwd 'abs_path' ;
use IO::Interactive qw{ interactive } ;

my $command = join ' ' ,
    qw{gconftool -t string -s /desktop/gnome/background/picture_filename} ;

my $img = shift @ARGV ;
my $bg  = abs_path $img ;

say { interactive } $bg ;
say qx{$command $bg} ;

IO::Interactive is simlarly cool, but we'll get into that later.

1 comment:

  1. I use Perl abs_path in both my Perl scripts and my Korn shell scripts as the most reliable way to locate the true path of the script. I like to make it easy to plop my scripts in any directory and not use hard coded paths, and Cwd is super for that. The less time spent editing config files the better!

    Yours,
    Tom

    ReplyDelete