in reply to newbie quesiton:how to open file in crob job?

Can I get the path infomation about current perl script ? If not , I can't know which is the full path of the config file because I can't force other guys install the perl script on the desired directory. thanks!
  • Comment on Re: newbie quesiton:how to open file in crob job?

Replies are listed 'Best First'.
Re: Re: newbie quesiton:how to open file in crob job?
by graff (Chancellor) on Mar 29, 2004 at 04:27 UTC
    Check out "perldoc Cwd" -- the Cwd module is part of the core distribution (everyone who has perl5 has this module):
    use Cwd; # ... my $cwd = getcwd(); # ...
    Also, if you are confident that the config file is always installed in the same directory as the perl script, then you can check the vale of $0 (that's "dollar-sign, digit-zero"):
    use File::Basename; # another core module # ... my $script_path = ( fileparse( $0 ))[1]; # look for config file in $s +cript_path # (update: as peckingham points out, "dirname()" is easier)
Re: Re: newbie quesiton:how to open file in crob job?
by pbeckingham (Parson) on Mar 29, 2004 at 04:15 UTC

    Try this:

    use File::Basename; my $cwd = dirname $0;

Re: Re: newbie quesiton:how to open file in crob job?
by flyingmoose (Priest) on Mar 29, 2004 at 14:16 UTC
    If you can't force them to specify where they are installing it, it is still fair game to have a config file where they have to list where they installed the app. And if you ship an install.pl or an install.sh script, or package an RPM, it's fair game for you to specify where your stuff gets installed. Sounds like you need to exert a little more control over your users. And then, even then, use absolute pathing versus a relative solution. Relative pathing has it's place, but avoid it when you can.