Mahdi A Sbeih wrote:
>
> I am using the below code:
>
> $fmtFile = `$dpImportCmd`;
> ..
> ..
> unlink($fmtFile) || die "unable to remove $fmtFile\n";
>
>
> dpImportCmd, is a program that generates a text file, this text file
> name is now in the variable: $fmtFile. Later in the program, I want to
> delete this file, but it fails. I don't know why.
>
> In the perl cookbook, it says "The backticks do not return until the
> called program exits"
>
> Is this related?

The book means that backticks don't return /control/ until the comand is
complete. That means that your Perl program is suspended until then and can't go
on to execute the unlink() until everything's finished. So no, that's not your
problem.

What is likely to be wrong is that dpImportCmd tags a newline onto the end of 
its
output, which is then an invalid filename and cannot be used in a call to
unlink(). Things will probably come together if jou just do chomp($fmtFile)
first, but /please/ check carefully the contents of your string before you just
go ahead and do this as there may be leading whitespace or even multi-line
output. An easy way to see non-printables in a string is to use URI::Escape if
you have the module installed.

  use URI::Escape;
  print uri_escape "  abc\n\n";

outputs

  %20%20abc.txt%0A%0A

so

  use URI::Escape;
  print uri_escape $fmtFile;

will show you what is hiding in your string variable.

HTH,

Rob

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to