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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.