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

That's because your backslashes get "eaten" by the double quotes in perl.

Use q{} instead of the double quotes.

Note also that pax allows any delimiter instead of /. Choosing a different one means you don't need backslashes at all.

Replies are listed 'Best First'.
Re^2: Calling pax within a perl script (was stupid substitution question)
by viffer (Beadle) on Aug 11, 2010 at 11:56 UTC
    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 '/'?

      $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'";