On Wed, Jul 25, 2001 at 02:03:30PM +0100, Yvonne Murphy wrote:
> Hi all,
> Thanks for all your help with previous questions I've had. What I need
> to figure out now is how I can strip the actual directory from the
> following pathname that I have stored in a variable :
> 
> (Just one sample of what I have but there will be different variations
> of the $pathname below)
> 
> $pathname = /home/username/folders/test/bar.h
> 
> So what I really need to be able to do is remove the filename from the
> end of the path and once I have the new path I want to be able  to
> change to that directory.
> 
> So I want to change to say '/home/username/folders/test'

    use File::Basename qw(dirname);

    my $dirname = dirname($pathname);
    chdir($dirname)
        || die("Unable to change directory to \"$dirname\": \l$!.\n");

see perldoc File::Basename and perldoc -f chdir.

You will likely see others suggest a regex, instead of using
File::Basename::dirname.  A regex works, but is not necessarily portable,
and is less readable, so you should weigh the benefits against the costs.


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to