littlemonk has asked for the wisdom of the Perl Monks concerning the following question:

i have a directory called dir1 which contains no of file wit .xml extension .I want o replace tht .xml extension with .txt ..plz suggest me a good way thanks in advance

Replies are listed 'Best First'.
Re: perl code to replace
by Corion (Patriarch) on Feb 10, 2011 at 12:43 UTC

    You don't show us any code, so I won't show any code either:

    • rename for renaming files
    • perlre for replacing one part of text with another part of text, also perlop for the s/// operator
    • glob respectively File::Glob for bsd_glob

    Another approach, which I often prefer, is to output shell commands via print, which I then, after close inspection, pipe into another shell.

Re: perl code to replace
by moritz (Cardinal) on Feb 10, 2011 at 12:38 UTC
      And if you don't have it, it is on CPAN.
Re: perl code to replace
by hsinclai (Deacon) on Feb 10, 2011 at 14:02 UTC
      Your bash script replaces filename like "xml.xml" to "txt.xml". I think you need to change the script as follows inorder to work as expected,

      mv $N ${N/%xml/txt}
Re: perl code to replace
by jethro (Monsignor) on Feb 10, 2011 at 12:44 UTC
    There is also the 'mmv' command, if you are on linux