Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

substitution problem

Status
Not open for further replies.

myggel

Programmer
Dec 11, 2005
15
DE
hi there,

I got a problem with substitution.
example string(I read that string from a file):
dont know why "it is that" way
if I substitute with:
$three=~s/"/-eee-/g;
and print it with:
print "$three\n";
prints: dont know why -eee-it is that-eee- way
looks fine, but if i print to a file:
print NEW_CFG_FILE "HOSTNAME "."\""."$three"."\""."\n";
prints: HOSTNAME "dont know why "it is that" way"
it takes the $three before substitution. why?

thanks for any help
michael
 
seems that the substitution is no tbeing made to $three or the subsitution is being made after you print it to the file. Without seeing your code nobody can say for sure though.
 
my code looks like:
Code:
#read from a file in $three

    $three=~s/"/-eee-/g;
    print "$three\n"; #prints correct output
    open(NEW_CFG_FILE, ">" ...){
    ...
    print NEW_CFG_FILE "HOSTNAME "."\""."$three"."\""."\n"; #prints incorrect output
    print $three."\n"; #printscorrect output
...
output would look like

hello \"world\"
HOSTNAME "hello "world" "
hello \"world\"

i don't understand why the $three differ.
 
looks like you have the quotes incorrect in the line that prints to file, try like this:

Code:
print NEW_CFG_FILE 'HOSTNAME\' . $three . '\' . "\n";
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top