On Oct 21, 2006, at 9:52 AM, xavier mas wrote:

Dear all,

Hi Xavier!

I'm trying to rename a bunch of files to the estination names included in a prepared files calling the system function "mv" inside a while loop (that
reads the destination files one by one).

But when doing this, I get an error saying a destiantion operand is missing in
line calling the system. Doesn't matter if I use double (for Perl
interpretaton)  or single quotes (for system interpretation).

If doing same thing on system bash line it works. What could be the reason for that behavior? I need, anyway through Perl programm due to the big ammount of
files I have to rename.

...
cont = 0;
while (<FILE_IN>) {
cont++

I bet the culprit are those barewords, write $cont instead. It is good to enable strictness and warnings always, they catch lots of potential bugs like that one.

$file_out = $_;
$file_in = $cont;
system "mv $file_in $file_out";}

Shelling out has always its risks. Here we are assuming names do not contain any space (which may be the case in your script). For the same price you can robustely use the builtin rename or the move/mv subroutines from the standard module File::Copy.

-- fxn




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