Replacement problem

Discussion in 'Perl Misc' started by prasanna bhat mavinkuli, Mar 2, 2005.

  1. Hi all,

    Iam wet behind the ears as for as Perl is concerned. I have got
    a problem, well its a real puzzle for a fresher like me.
    In my code i just want to create a source directory structure in
    a target directory. I am finding all the subdirectories in the
    source directory and creating it in the target directory during run
    time. And i am failing to do so because directory name
    contains(+,- etc). So its a metacharacter problem. Also I want to
    retain the directory names as it is. So here is the piece of
    code, but i have initialized values for the arrays to illustrate,

    @stor_array=("/dir+a/dir2","/dir+a/dir2/lost+found/","/dir+a/dir2/kallu+mat","/dir+a/dir2/kallu+mat","/dir+a/dir2/kallu+ma-jon");

    $dir="dir+a";
    $temp="target";
    foreach (@stor_array){
    s/$dir/$temp\/Files\//;
    print $_ ,"\n";
    }
    Please somebody help me to achieve the replacement.

    thanks in advance
    Prasanna Bhat Mavinkuli
     
    prasanna bhat mavinkuli, Mar 2, 2005
    #1
    1. Advertising

  2. prasanna bhat mavinkuli wrote:
    > In my code i just want to create a source directory structure in
    > a target directory. I am finding all the subdirectories in the
    > source directory and creating it in the target directory during run
    > time. And i am failing to do so because directory name
    > contains(+,- etc). So its a metacharacter problem.


    You probably want \Q. See "perldoc perlre".

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Mar 2, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Youhanna Mounir
    Replies:
    3
    Views:
    567
  2. Henner Graubitz
    Replies:
    11
    Views:
    630
    Virgil Green
    May 25, 2004
  3. Replies:
    7
    Views:
    112
    Ross Bamford
    Mar 1, 2006
  4. ridcully
    Replies:
    4
    Views:
    129
  5. String replacement problem

    , Jun 18, 2005, in forum: Javascript
    Replies:
    3
    Views:
    93
    Lasse Reichstein Nielsen
    Jun 18, 2005
Loading...

Share This Page