Re: [問題] 取得程式的當下目錄

看板Perl作者時間15年前 (2009/12/09 13:24), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
※ 引述《heliosy (這一欄是要做啥用的)》之銘言: : 請問一下 : 我如果把一支程式a.pl放在C:\test\之下 : 那可以用什麼方式讓它自己取得test這個資料夾名稱呢 : 謝謝 可以試著比較一下 $0、Cwd 與 FindBin,如下: 程式放在 /tmp/test/test.pl ====================================================== use strict; use warnings; use Cwd; use FindBin qw($Bin); use File::Basename; print q{$0 = }, $0 , "\n"; print q{getcwd() = }, getcwd(), "\n"; print q{$Bin = }, $Bin , "\n"; print basename($Bin), "\n"; print dirname($Bin) , "\n"; ====================================================== # cd /usr/local # perl /tmp/test/test.pl $0 = /tmp/test/test.pl getcwd() = /usr/local $Bin = /tmp/test test /tmp 取得 basename 或 dirname,則再使用 File::Basename。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.114.64.130

12/09 14:00, , 1F
12/09 14:00, 1F
文章代碼(AID): #1B7pHwBN (Perl)
討論串 (同標題文章)
文章代碼(AID): #1B7pHwBN (Perl)