By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,691 Members | 1,997 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,691 IT Pros & Developers. It's quick & easy.

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

P: 18
I have a template file whose line reads as:

CREATE TABLESPACE "CUSTTBS" LOGGING DATAFILE '{DBFILE_PATH}cust.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_create_tablespaces_generic_template.sql ") || die "Can not Open file : $!";
@lines = <FILE>;
close (FILE);

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

The array arr_db_file_paths 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)
May 26 '10 #1
Share this Question
Share on Google+
1 Reply


Expert
P: 70
Try to escape your backslashes:

Expand|Select|Wrap|Line Numbers
  1. my @arr_db_file_paths = ("c:\\o\\", "d:\\o\\", "e:\\o\\", "f:\\o\\");
May 26 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.