in reply to Re: Usig file name without backslash escape
in thread Usig file name without backslash escape

Ups, sorry I did not check the code before sending a question. This is corrected code:
#!/usr/bin/perl use strict; use warnings; my $newDir = "/home/iphone/Maildir/new"; my $curDir = "/home/iphone/MailDir/cur"; my $file; opendir(DIR, "$newDir"); my @FILES= readdir(DIR); closedir DIR; foreach (@FILES) { $file = $_; my $newFile=$newDir."\/".$file; my $curFile=$curDir."\/".$file; print "$newFile\n"; print "$curFile\n"; rename $newFile, $curFile; }
Response that I am getting is this: /home/iphone/Maildir/new/. /home/iphone/MailDir/cur/. /home/iphone/Maildir/new/1340841279.M908367P21767.krasowski,S=2294,W=2338 /home/iphone/MailDir/cur/1340841279.M908367P21767.krasowski,S=2294,W=2338 /home/iphone/Maildir/new/.. /home/iphone/MailDir/cur/.. /home/iphone/Maildir/new/1340841583.M454288P21927.krasowski,S=2339,W=2384 /home/iphone/MailDir/cur/1340841583.M454288P21927.krasowski,S=2339,W=2384 But no file is moved. Hmm, Any idea what is th problem? Why I can not move these files?? Thanks Robert

Replies are listed 'Best First'.
Re^3: Usig file name without backslash escape
by aaron_baugher (Curate) on Jun 28, 2012 at 03:26 UTC

    Have you tried asking Perl what the problem is?

    rename $newFile, $curFile or die $!;

    Aaron B.
    Available for small or large Perl jobs; see my home node.

Re^3: Using file name without backslash escape
by Athanasius (Archbishop) on Jun 28, 2012 at 03:24 UTC

    From rename in perldoc:

    Behavior of this function varies wildly depending on your system implementation. For example, it will usually not work across file system boundaries, even though the system mv command sometimes compensates for this. Other restrictions include whether it works on directories [...]
    For a platform independent move function look at the File::Copy module.

    — which is why you should prefer the solution given by Kenosis, below.

    Athanasius <°(((><contra mundum