Hello everybody,
I wanted to learn a bit more about how to handle errors when I am working with 
files, so I wrote this simple script to start with it where you can see that 
first I show the normal perl errors variables, then I try to delete a file and 
finally I show the errors variables again.
The file I try to delete exists and it is at the same directory and after the 
script the file is deleted, so it works.
What surprised me is that at the end of the script the '$!' is 'No such file or 
directory' and '$^E' is 'The system cannot find the file specified' though the 
file was deleted correctly, :-?.
  
My idea was to treat the '$!' when I am working with files but with this 
results I don't see how.
Let me tell you I am using this version of perl with Windows and I tried it 
both, Win2k and WinXP:
This is perl, v5.8.7 built for MSWin32-x86-multi-thread
(with 14 registered patches, see perl -V for more detail)
   
  Here it is the script and afterwards there is the STDOUT exit.
   
  ----------------------------------------------------
#!/usr/bin/perl -w
  use strict;
  
print "\n\n\nBEFORE:\n-----\n";
print '$@'." is ->$@<-\n";
print '$!'." is ->$!<-\n";
print '$^E'." is ->$^E<-\n";
print '$?'." is ->$?<-\n\n\n";
   
  # I tried with open and with system()
  #open (RD , "del pepe.txt |") or die "I cannot RD\n";
  system ("del pepe.txt");
      
print "AFTER:\n----\n";
print '$@'." is ->$@<-\n";
print '$!'." is ->$!<-\n";
print '$^E'." is ->$^E<-\n";
print '$?'." is ->$?<-\n\n\n";
 
#close RD;      
-------------------------------------------------------
   
  ...and I got this as result:
   
  -------------------------------------------------------
BEFORE:
-----
$@ is -><-
$! is -><-
$^E is -><-
$? is ->0<-
  
 
  
AFTER:
----
$@ is -><-
$! is ->No such file or directory<-
$^E is ->The system cannot find the file specified<-
$? is ->0<
   
  ------------------------------------------------------------
  
Questions:

1.- Why a have the '$!' and '$^E' set as it could not find the file when in 
reality it could?
  I tried with 'system()' and with 'open' with the same results. :-(
  
Any help is welcome,
Thanks in advance.
  Regards.


       
---------------------------------
Looking for last minute shopping deals?  Find them fast with Yahoo! Search.

Reply via email to