Home > Archive > PERL Beginners > October 2006 > calling system
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Xavier Mas 2006-10-21, 7:56 am |
| Dear all,
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++
$file_out = $_;
$file_in = $cont;
system "mv $file_in $file_out";}
....
--
Xavier Mas
| |
| Jeff Pang 2006-10-21, 7:56 am |
|
>...
>cont = 0;
>while (<FILE_IN> ) {
>cont++
>$file_out = $_;
>$file_in = $cont;
>system "mv $file_in $file_out";}
>...
Hello,
I think it's better to use perl's "rename" instead of system call "mv".
See 'perldoc -f rename'.
--
Books below translated by me to Chinese.
Practical mod_perl: http://home.earthlink.net/~pangj/mod_perl/
Squid the Definitive Guide: http://home.earthlink.net/~pangj/squid/
| |
| Xavier Noria 2006-10-21, 7:56 am |
| 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
| |
| Xavier Mas 2006-10-21, 7:56 am |
| A Dissabte 21 Octubre 2006 11:18, Xavier Noria va escriure:
> On Oct 21, 2006, at 9:52 AM, xavier mas wrote:
>
> Hi Xavier!
>
>
> 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.
>
>
> 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
Thanks Xavier, I'll try your suggestions.
--
Xavier Mas
| |
| Andrew tanenbaum 2006-10-21, 6:57 pm |
| On Sat, 21 Oct 2006 04:15:23 -0400 (EDT) , Jeff Pang <pangj@earthlink.net> wrote:
>
$cont = 0;
[color=darkred]
$cont++ ;
[color=darkred]
>
Isn't the right way?
________________________________________
_______________________
Hot new product - Spider Networks introduces stunning online ePortfolio solution for students and teachers
http://www.spider-networks.net/solu...eportfolio.html
| |
| nobull67@gmail.com 2006-10-22, 7:57 am |
|
Jeff Pang wrote:
>
> Hello,
>
> I think it's better to use perl's "rename" instead of system call "mv".
> See 'perldoc -f rename'.
Unless,of course, you really want to be able to move files not just
rename them. See File::Copy.
|
|
|
|
|