Below is the set of files in my directory.

ITEM_1.PRODUCTS.sold

ITEM_2.PRODUCTS.sold

ITEM_3.PRODUCTS.sold

ITEM_4.PRODUCTS.sold

ITEM_5.PRODUCTS.sold

ITEM_6.PRODUCTS.sold

With below code I am able to rename the files as

ITEM_1.PRODUCTS.sold

to

ITEM_1.PRODUCTS.ordered

#/usr/bin/perl use strict; use warnings; my $dir = '/local/usr/prod/'; my $exp = 'PRODUCTS' my $code = 'ITEM_1' my @filelist =glob "${dir}*{$code}*{exp}*failed*"; foreach(@fileList){ next if -d; my$ oldname=$_; s/sold/ordered/; rename $oldname,$_ or $_=$oldname, warn "can"t rename $oldnme to $_: $!" }

However now I want my variable to be passed as

my $code = 'ITEM_1 ,ITEM_2 ,ITEM_3 ,ITEM_4 ,ITEM_5 ,ITEM_6';

and rename all the files to

ITEM_1.PRODUCTS.ordered

ITEM_2.PRODUCTS.ordered

ITEM_3.PRODUCTS.ordered

ITEM_4.PRODUCTS.ordered

ITEM_5.PRODUCTS.ordered

ITEM_6.PRODUCTS.ordered

Please help. Thanks.


In reply to Perl Rename set of files by Magnolia25

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.