http://www.perlmonks.org?node_id=975598


in reply to Creating Tarballs in a perl scripts

First of all: Do you really want the outout of tar?

If not you should not use backticks but system.

Then it all depends on what your variables acually contain as the string you use inside the backticks will be interpreted by a shell.

If for example your $DEST variable contains "/tmp/*" then it is clear why no hidden files make it to the tar-archive - the shell globs "*" and will not pass any hidden files to tar.

The shell used in backticks is usually /bin/sh (not bash - bash-settings are irrelevant here).

If your $DEST does not contain shell meta-characters then I cannot see any reason why your command should not work, but that would not be a Perl-related problem.

Finallly if you use system you can avoid a shell by calling it like

system("/bin/tar", "-cfz", $output_file, $directory)

Replies are listed 'Best First'.
Re^2: Creating Tarballs in a perl scripts
by Lotus1 (Vicar) on Jun 11, 2012 at 19:39 UTC

    First of all: Do you really want the outout of tar?

    If not you should not use backticks but system.

    Perhaps the OP doesn't want to see the output on the display.

      Perhaps the OP doesn't want to see the output on the display.
      IMO it would be natural (and easier to understand) in this case to redirect to the bit bucket...

      -- 
      Ronald Fischer <ynnor@mm.st>
Re^2: Creating Tarballs in a perl scripts
by mdw1982 (Initiate) on Jun 12, 2012 at 16:54 UTC

    First, thank you all for your replies; much appreciated as this has been bugging me for quite some time.

    Morgan, your solution was just what I needed, interestingly though when I tried using system() before I couldn't get it to work as I wanted. Implementing the way you exampled did the trick.

    At first it wasn't working correctly, but that led me to a glaring error in the code that I'd been missing. All is fixed now and working nicely.

    Thank you all for your assistance.