in reply to tar sytem command

It's pretty simple, like grantm said:
my $archive = "/some/dir/archive.tar.gz"; # Split the filename off of the directory using a regular expression my ($dir, $filename) = $archive =~ m#^(.*)/([^/]+)$#; # Switch in to the directory with the archive chdir($dir) || die "Invalid path $dir\n"; # Extract the archive using 'tar' system("tar","-xvzf",$filename);
That's generic, and should do the job for you.

Replies are listed 'Best First'.
Re: Re: tar sytem command
by grantm (Parson) on Oct 29, 2002 at 07:22 UTC

    I'd be inclined to use:

    use File::Basename; my $archive = "/some/dir/archive.tar.gz"; my ($filename, $dir) = fileparse($archive);

    Of course you could argue that it's fairly safe to assume a system that has 'tar' installed probably also uses '/' for a directory separator :-)

      Good point. I was thinking there was a module, but couldn't make the mental leap past File::Path which is not what I was looking for.

      By the way, how do you find out what the directory separator is? Check $/ and guess?
        By the way, how do you find out what the directory separator is?

        File::Spec is another core module (comes with Perl) that can be used for file pathname manipulations such as splitting or combining a path into the individual directory componenets. File::Spec takes care of the details so you don't even need to worry what the directory separator is.