http://qs1969.pair.com?node_id=206907

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am looking to find a string in a text file and replace with a new value, here is the code I am having difficulty with, can anyone help find out why I can not print to the text file with the new value found? Thank you!!! Here is the test.txt
<?--1-News1--> <b>This is option News 1 of 1</b> </?--1-News1--> <?--1-Weather2of1--> <b>This is option Weather 2 of 1</b> </?--1-Weather2of1--> <?--1-Stock3of1--> <b>This is option Stock 3 of 1</b> </?--1-Stock3of1--> <?--2-Second1of2--> <b>Option Second 1 of 2</b> </?--2-Second1of2--> <?--3-Third1of3--> <b>Option Third 1 of 3</b> </?--3-Third1of3-->


Here is the program I am trying to write:

use strict; use CGI qw(:header); use CGI::Carp qw(fatalsToBrowser); use CGI qw/:standard/; print "content-type: text/html\n\n"; #&getdata(%in); &getdata; #$location = $in{'location'}; #$obj_name = $in{'obj_name'}; #$page = $in{'page'}; #The value on these variable are hard coded for testing #my $location=param('location'); $location="1"; #my $obj_name=param('obj_name'); $obj_name="News1"; $page="Testing New Content for Object ONE TWO"; my $filename="test.txt"; my $template_data = "unsecure/".$filename; undef $/; # Slurp mode open(DATA_IN, "$template_data") || print "Can't open output file1: $te +mplate_data\n"; #binmode DATA_IN; $_ = <DATA_IN>; #close DATA_IN; while(/<\?--([^-]*)-([^-]*)-->(.*?)<\/\?--([^-]*)-([^-]*)-->/sg){ #<?--1-News1--> #<b>This is option News 1 of 1</b> #</?--1-News1--> $a=$1;$b=$2;$c=$3;$d=$4;$e=$5; if ($a eq $location){ if($b eq $obj_name) { #$c=~s/$c/$page/ig; $c=$page; open( DATA_OUT, ">/unsecure/test.new" ) or d +ie "$!\n"; print DATA_OUT "<?--$a-$b-->\n"; print DATA_OUT "$c\n"; print DATA_OUT "</?--$d-$e-->\n"; + } } } #print DATA_OUT; close DATA_OUT; close DATA_IN; #print "content-type: text/html\n\n"; print "<b> EDITOR</b><br><br>\n"; print "<hr>"; print "You're about to change location:&nbsp;&nbsp;&nbsp;&nbsp;<b>$loc +ation</b>"; print "<br>\n"; print "Viewing object name:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>$obj +_name</b>"; print "<hr>\n"; print "<br><br><br><br>\n"; print "<b>$page</b>"; print "<br><br><br><br>";; print "<hr>"; print "<form>\n"; print " <input type=\"submit\" value=\"submit\">\n"; print "</form>\n";

I cant see where the problem is. Thanks again!!!