Tested on Linux:
#!/usr/bin/perl use strict; use warnings; use Cwd 'abs_path'; sub in_dir { $_ = shift; m|(.*)/.*$|; ## we take advantage of greediness $1 || "/"; } my $self = abs_path $0; my $stripped = in_dir in_dir $self; print "$self -> $stripped\n"; __OUTPUT__ $ # there's a copy in my home and other in / $ ./a.pl /home/hue/a.pl -> /home $ /a.pl /a.pl -> / $ cd / $ ./a.pl /a.pl -> /
UPDATE: I knew I was reinventing the wheel, I just didn't find that File::Basename thingy.
--
David Serrano
In reply to Re: Current Directory
by Hue-Bond
in thread Current Directory
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |