CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: single to double quote conversion: Edit Log



FlayedOne
Novice

Jan 26, 2010, 3:46 PM


Views: 2585
single to double quote conversion

Hello,

The problem seems really stupid, so either I'm missing something, or... okay, I'm sure I'm missing something.

My CGI script gets some string variables from some PHP/JS/AJAX over which I have no control through POST method. The problem is those variables are meant to be used as a pattern, some text fragment that is meant to replace matches, and a big text that is meant to be searched. Everything works great beside one simple thing - those strings I get are singlequoted, therefore I can't use $n variables. Here is the code:


Code
#!c:\perl\bin\perl.exe -wT  

use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);

print header;

my %form;
foreach my $p (param()) {
$form{$p} = param($p);
}

$regexp = $form{"regexp"};
$regexp =~ s/\s+$//g;
$regexp =~ s/\\(\'|\"|\\)/$1/g;

$changeto = $form{"changeto"};
$changeto =~ s/\s+$//g;
$changeto =~ s/\\(\'|\"|\\)/$1/g;



$answer1 = $form{"content"};
$answer1 =~ s/\s+$//g;
$answer1 =~ s/$regexp/<span class=\\\"green\\\">$&<\/span>/g;

print "{\"div1\":\"".$answer1."\"";

$answer2 = $form{"content"};
$answer2 =~ s/\s+$//g;

if($answer2)
{
$answer2 =~ s/($regexp)/<span class=\\\"red\\\">$changeto<\/span>/g;
print ",\"div2\":\"".$answer2."\"";
}
print "}";


How do I convert a singlequoted string to a doublequoted one?


(This post was edited by FlayedOne on Jan 27, 2010, 2:56 AM)


Edit Log:
Post edited by FlayedOne (Novice) on Jan 26, 2010, 3:48 PM
Post edited by FlayedOne (Novice) on Jan 27, 2010, 2:56 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives