regarding replacing a placeholder by windows / unix style path in perl

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gskbond
    New Member
    • Oct 2009
    • 18

    regarding replacing a placeholder by windows / unix style path in perl

    I have a template file whose line reads as:

    CREATE TABLESPACE "CUSTTBS" LOGGING DATAFILE '{DBFILE_PATH}c ust.dbf' SIZE 1000M REUSE AUTOEXTEND ON NEXT 100M MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO ;

    The place holder is {DBFILE_PATH}

    I am replacing this by contents in a perl array which has paths in it

    The code to open a file replace contents and write new file is:

    @lines = ();
    $line = "";
    open (FILE, "oracleds2_crea te_tablespaces_ generic_templat e.sql") || die "Can not Open file : $!";
    @lines = <FILE>;
    close (FILE);

    my $i_Cnt = 0;
    #print "@arr_db_file_p aths \n";
    foreach $line (@lines)
    {
    $line =~ s/{DBFILE_PATH}/$arr_db_file_pa ths[$i_Cnt]/g;
    print "$line \n ";
    $i_Cnt++;
    }
    open (NEWFILE, ">oracleds2_cre ate_tablespaces _generic.sql") || die "Creating new file to write failed : $!";
    print NEWFILE @lines;
    close (NEWFILE);

    The array arr_db_file_pat hs has paths ("c:\o\" "d:\o\" "e:\o\" "f:\o\")
    The template file has four such lines with four {DBFILE_PATH} placeholders.

    The paths array can have either unix or windows style paths.

    The file is not getting written correctly.

    Instead placeholder is getting replaced by blank.

    The output file has line as :

    CREATE TABLESPACE "CUSTTBS" LOGGING DATAFILE 'cust.dbf' SIZE 1000M REUSE AUTOEXTEND ON NEXT 100M MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;

    Is there any other way to find a solution for this? (I mean handling \ or / in paths and replace statements in perl)
  • toolic
    Recognized Expert New Member
    • Sep 2009
    • 70

    #2
    Try to escape your backslashes:

    Code:
    my @arr_db_file_paths = ("c:\\o\\", "d:\\o\\", "e:\\o\\", "f:\\o\\");

    Comment

    Working...