SPUG: finding directory of script
Matt Tucker
tuck at whistlingfish.net
Fri Feb 15 11:52:23 CST 2002
-- Richard Anderson <richard at richard-anderson.org> spake thusly:
> use Cwd;
> ($dir = $0) =~ s,(.*)/[^/]+$,$1,;
> unless ($dir =~ /^\//) {
> $dir = getcwd() . '/' . $dir; # Prefix current working
> directory to relative pathname
> $dir =~ s/\/\.$//; # Strip trailing /.
> $dir =~ s#/\.\./#/#g; # Not necessary, but
> aesthetically better
> }
I always cringe when I see someone escaping slashings in a regex. Try
using an alternate delimiter; it'll be much easier to read. Sure
TMTOWTDI, but in my opinion some of them are wrong. ;-)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
Url : http://mail.pm.org/archives/spug-list/attachments/20020215/230d12c3/attachment.bin
More information about the spug-list
mailing list