in reply to Re: Perl Script own path
in thread Perl Script own path
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>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Perl Script own path
by Marshall (Canon) on Jul 27, 2011 at 07:51 UTC | |
by Anonymous Monk on Jul 27, 2011 at 07:57 UTC | |
by Marshall (Canon) on Jul 27, 2011 at 08:20 UTC |