Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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
Re^2: Usig file name without backslash escape
by AnomalousMonk (Abbot) 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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://978864]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (14)
As of 2014-12-18 09:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (48 votes), past polls