Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: -e on windows giving error

by BrowserUk (Pope)
on Nov 17, 2011 at 23:28 UTC ( #938704=note: print w/ replies, xml ) Need Help??


in reply to -e on windows giving error

my objective here is to get the drive which my perl script lies in,

If you inspect the built-in variable, $0 (that's zero not oh), it will tell you the full path of the current script including the drive. Eg:

print $0;; C:\Perl64\bin\p1.pl

So, my( $drive ) = $0 =~ m[^(.)]; will give you the drive letter directly.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.


Comment on Re: -e on windows giving error
Select or Download Code
Re^2: -e on windows giving error
by Rudolf (Monk) on Nov 17, 2011 at 23:30 UTC
    Oh man, thank you so much everyone! I have found my solution and learned a lot today, Im new to perlmonks and already find the community very welcoming and helpfull! thanks and best wishes, Rudy

      The solution BrowserUk rarely works. It requires an absolute path when launching the script (common for some, rare for others), and then only if the absolute path starts with something of the form "D:" (extremely common).

      I've posted a more robust version here. It handles relatives paths, and even more exotic drive volume names.

        The solution BrowserUk rarely works. It requires an absolute path when launching the script

        No it does not!

        C:\Perl64\bin>p1 [0] Perl> print $0;; C:\Perl64\bin\p1.pl [0] Perl> Terminating on signal SIGINT(2) C:\Perl64\bin>.\p1.pl [0] Perl> print $0;; C:\Perl64\bin\p1.pl [0] Perl> Terminating on signal SIGINT(2) C:\Perl64\bin>cd \test C:\test>p1 [0] Perl> print $0;; C:\Perl64\bin\p1.pl

        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

      If for some obscure reason you do not use file associations to invoke your scripts, and are in the habit of using tortuous relative path constructions to find them, then a simple step would sort out the mess you (probably didn't) create:

      c:\test>perl ..\tmp\..\test\..\Perl64\site\.\lib\..\..\bin\p1.pl Perl> print scalar Win32::GetFullPathName( $0 );; c:\Perl64\bin\p1.pl

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://938704]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2014-09-17 00:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (55 votes), past polls