Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: Usig file name without backslash escape

by zachhilbert (Initiate)
on Jun 28, 2012 at 08:55 UTC ( #978864=note: print w/replies, xml ) Need Help??

in reply to Usig file name without backslash escape

I was able to get the script to work using filenames similar to yours by this adding 2 lines after $file = $_:

$file =~ s/\=/\=g;
$file =~ s/\,/\,/g;

This just catches the '=' and ',' in the first half, and replaces those with '\=' and '\,' respectively. I had a similar issue as yours in the past and this is how I addressed it. You may also run into '.' and '..' erroring out, but the other files should move. I would also add rename ... or die syntax as was suggested by Aaron.

Hope this helps.
  • Comment on Re: Usig file name without backslash escape

Replies are listed 'Best First'.
Re^2: Usig file name without backslash escape
by AnomalousMonk (Chancellor) on Jun 28, 2012 at 20:50 UTC

    In a regex or double-quoteish string, a  \ (backslash) escaped = or , is no different than the unescaped character.

    >perl -wMstrict -le "my $file = 'a=b,c=d,e'; $file =~ s/\=/\=/g; $file =~ s/\,/\,/g; print qq{unchanged: '$file'}; " unchanged: 'a=b,c=d,e'
      I got it working that way:
      <code> #!/usr/bin/perl use strict; use warnings; my $file; opendir(DIR, "$newDir"); my @FILES= readdir(DIR); closedir DIR; foreach (@FILES) { $file = $_; if ($file ne "..") { if ($file ne ".") { my $newFile = "/home/iphone/Maildir/ne +w/$file"; my $curFile = "/home/iphone/Maildir/cu +r/$file"; rename $newFile, $curFile or die $!; } } }
      </code> Thanks for help Robert

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://978864]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2018-05-26 18:34 GMT
Find Nodes?
    Voting Booth?