concatenate the result of cwd() and basename($0) with intervening "/" to get the full path of the script in a OS independent way.
What does the value of Cwd::cwd() have to do with the path of the Perl script? There's no general correlation.
C:\WINDOWS>type C:\Temp\WhereAmI.pl #!perl use strict; use warnings; use Cwd; use English; use File::Basename; my $basename = File::Basename::basename($PROGRAM_NAME); my $abs_path = Cwd::abs_path($PROGRAM_NAME); my $dirname = File::Basename::dirname($abs_path); my $cwd = Cwd::cwd(); print "\$PROGRAM_NAME: $PROGRAM_NAME\n"; print "\$File::Basename::basename(\$PROGRAM_NAME): $basename\n"; print "\$Cwd::abs_path(\$PROGRAM_NAME): $abs_path\n"; print "\$File::Basename::dirname(\$abs_path): $dirname\n"; print "\$Cwd::cwd(): $cwd\n"; exit 0; C:\WINDOWS>perl \Temp\WhereAmI.pl $PROGRAM_NAME: \Temp\WhereAmI.pl $File::Basename::basename($PROGRAM_NAME): WhereAmI.pl $Cwd::abs_path($PROGRAM_NAME): C:/Temp/WhereAmI.pl $File::Basename::dirname($abs_path): C:/Temp $Cwd::cwd(): C:/WINDOWS C:\WINDOWS>
In reply to Re^2: Perl Script own path
by Jim
in thread Perl Script own path
by muzammil18
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |