Excellent points, all

From: Wiggins d'Anconia [mailto:[EMAIL PROTECTED] 
>>> And a reason why using a shell command to copy a file is a bad idea.
<<<

Well, the 'shell' and 'copy' association in this case is actually
something of a red herring. The point of this particular script is not
to copy files, it is to illustrate to a non-programmer an easy and dirty
way of executing a program and then capturing some 'results' for
analysis. In this case, the file copying batch program was used simply
because it produces readily verifiable results (either the .bak files
are there, one for each original file specified, or they're not.)

>>>opendir DIR2, '.' or die "Can't open directory for reading a second
time: $!";
my @after = readdir DIR2;
closedir DIR2; <<<

Well, I boiled the script down to essentials before posting it,
including taking out some error handling (not on these particular
commands though.) However, in this particular instance, there were no
errors to trap. The *dirs worked correctly, they just weren't picking up
the changes made to the directory because those changes were not visible
to Perl until after the file handle to the shell was closed or otherwise
reset.

>>> As an aside, if you must use a shell command you are better off
sticking with system, until you need the output which is provided by
backticks, only use the piped open form when you need to communicate
with the command you are running. <<<

I'm certain you're right. As it happens, in this particular instance the
script IS piping additional messages to the shell. Is open() the only
means of doing that?

daniel

--
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