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.
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!
ReplyDeleteYours,
Tom