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


in reply to Re: Calling pax within a perl script (was stupid substitution question)
in thread Calling pax within a perl script (was stupid substitution question)

Thank you - appreciate your help. Whilst this works perfectly for
my $cmd = q{pax -r -f /home/kev/pax.tar -s'/\/home\/kev\/pax\//\/data\/kev\/atlanta\/emtex\/invoices\//p'};

When the directory name has several nodes and the filename being paxed/untarred is a variable I guess it isn't interpolating correctly

$command= q{pax -r -f $file -s'/DirPart1.DirPart2.DirPart3/SubDir\//\/data\/kev\/atlanta\/emtex\/invoices\//p'};

I have tried several variants of this, such as
$command= q{pax -r -f $file -s'/DirPart1\.DirPart2\.DirPart3\/SubDir\//\/data\/kev\/atlanta\/emtex\/invoices\//p'};
When running this I get the error:
A file or directory in the path name does not exist.
which makes me think the string isn't being interpolated correctly.
I can see how using a different delimiter would obviate the need for using backslashes in the first example that works,
but in the second example don't I need escape backslashes for the '.' if not for the subdir '/'?

Replies are listed 'Best First'.
Re^3: Calling pax within a perl script (was stupid substitution question)
by JavaFan (Canon) on Aug 11, 2010 at 12:14 UTC
    $file won't interpolate inside q{}. A handful of alternatives:
    • $command = "pax -r -f $file -s'!DirPart1.DirPart2.DirPart3/SubDir/!/data/kev/atlanta/emtex/invoices/!p'"
    • $command = qq{pax -r -f $file } . q{-s'/DirPart1.DirPart2.DirPart3\/SubDir\//\/data\/kev\/atlanta\/emtex\/invoices\//p'};
    • $command = sprintf q{pax -r -f %s -s'/DirPart1.DirPart2.DirPart3/SubDir\//\/data\/kev\/atlanta\/emtex\/invoices\//p'}, $file;
    • $command= q{pax -r -f $file -s'/DirPart1.DirPart2.DirPart3/SubDir\//\/data\/kev\/atlanta\/emtex\/invoices\//p'}; $command =~ s/\$file/$file/;
    Or something else.
      Thanks VERY much for your help. *Finally* got this to work

      $file =~ s/TGZ/tar/; $dir = $file; $dir =~ s!\.S75\.T...tar!\/Invoices\/!; if ($file =~ /(PROD.OPTBL.X.K.)(R*)(.S75.T11.tar)/) { $run=$2; } $command = "pax -r -f $file -s'!$dir!/data/kev/atlanta/emtex/invoi +ces/R$run/!p'";