CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
How to check, if the script on current directory

 



digioleg54
User

Mar 29, 2017, 12:03 PM

Post #1 of 4 (857 views)
How to check, if the script on current directory Can't Post

Perl script is working on different directories and at the end I want to clean working directory. I have a variable $path_to_cur_dir = /path/to/dir
What command to use to check if the script is on current directory, and if not, then change directory to current.

In my opinion it is supposed to be something like
if ( ! -z $path_to_cur_dir)
{
chdir $path_to_cur_dir
}


(This post was edited by digioleg54 on Mar 29, 2017, 12:10 PM)


FishMonger
Veteran / Moderator

Mar 29, 2017, 1:31 PM

Post #2 of 4 (849 views)
Re: [digioleg54] How to check, if the script on current directory [In reply to] Can't Post

http://search.cpan.org/~rjbs/PathTools-3.62/Cwd.pm


Laurent_R
Veteran / Moderator

Mar 30, 2017, 5:37 AM

Post #3 of 4 (842 views)
Re: [digioleg54] How to check, if the script on current directory [In reply to] Can't Post

If you really want to know whether you're in the right directory, then use the module suggested by FishMonger, but do you really need to check? Why don't you simply issue the chdir command?


digioleg54
User

Mar 30, 2017, 6:00 AM

Post #4 of 4 (841 views)
Re: [Laurent_R] How to check, if the script on current directory [In reply to] Can't Post

I already found correct solutuion

if ( defined $dir_to_check and length $dir_to_check)
{
chdir $$dir_to_check
}

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives