Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Determining the directory the running script is in

by cLive ;-) (Prior)
on Jun 26, 2007 at 16:28 UTC ( #623451=perlquestion: print w/replies, xml ) Need Help??
cLive ;-) has asked for the wisdom of the Perl Monks concerning the following question:

I've been using this:
#!/usr/bin/perl use strict; use warnings; use Cwd 'abs_path'; my $script_dir = substr( abs_path($0), 0, rindex(abs_path($0),'/') ) print $script_dir.$/;
Seems a little long winded though... Is there a simpler answer?

Replies are listed 'Best First'.
Re: Determining the directory the running script is in
by Corion (Pope) on Jun 26, 2007 at 16:35 UTC

    How about

    use File::Basename 'dirname'; use Cwd 'abs_path'; my $script_dir = abs_path(dirname($0));
Re: Determining the directory the running script is in
by Fletch (Chancellor) on Jun 26, 2007 at 16:42 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://623451]
Approved by Corion
help
Chatterbox?
[Lady_Aleena]: File::Find doesn't have a simple sub wanted example, like get the name of the file.
[Discipulus]: there is also find2perl with your perl installation
[Discipulus]: and in the wanted sub you just calculate the duretion and add it the total, stop
[shmem]: sub wanted { push @files, $File::Find::name if $File::Find::name =~/\.mp3$/ }

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (13)
As of 2017-04-23 20:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (432 votes). Check out past polls.