I interpret the question as : I only want to run this script if it is invoked from the symlinked folder.
Use Path::Tiny if you want to stay portable (as posted earlier).
Check -l, readlink, and Cwd::abs_path to fill your needs.
#!perl use Cwd qw( getcwd abs_path ); my ($DIR, $CMD) = $0 =~ m{^(.*)/([^/]+)$}; ! $CMD && ! -d $DIR and ($DIR, $CMD) = (getcwd, $DIR); # "." in $PATH +and script invoked without ./ -l $DIR or die "$DIR is not the symlinked folder. Running like this is + dangerous!\n"; say "Current dir : ", getcwd; say "Invoking folder: ", $DIR; say "Symlink : ", readlink $DIR; say "Abs path: : ", abs_path $DIR;
$ mkdir -p tmp/test-a $ ln -s test-a tmp/test $ ln -s tmp/test test $ vi tmp/test/test.pl -- paste above code and save $ perl test/test.pl Current dir : /home/tux Invoking folder: test Symlink : tmp/test Abs path: : /home/tux/tmp/test-a
In reply to Re: Getting logical path from Perl?
by Tux
in thread Getting logical path from Perl?
by mathomp4
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |