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: Re: [FishMonger] single to double quote conversion: Edit Log



FlayedOne
Novice

Jan 27, 2010, 5:54 AM


Views: 2542
Re: [FishMonger] single to double quote conversion

I did what you said, but beside fixing how the code looks it doesn't change a thing.


Code
   

#!c:\perl\bin\perl.exe -T

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

print header;

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



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

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

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

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

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

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



I can't do this:


Code
   my %form = Vars;



because I get an error "word Vars not allowed while strict in use".

Here is an example. Imagine that I get this data, and put them in following variables:

Code
 $regexp = '([a-z]) \\1';    
$content = 'acabxxbxbx axxb a a';
$changeto = '$1';



I don't have any control over those strings. $regexp works great, and finds exactly what I want - "a a", but when doing substitution:

Code
   $answer2 =~ s/$regexp/<span class=\\\"red\\\">$changeto<\/span>/g;

$1 in $changeto is treated like literal text. That is to be expected, but I want to change the way it's treated so that it would be treated as a $1 variable.

Did that make more sense?


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


Edit Log:
Post edited by FlayedOne (Novice) on Jan 27, 2010, 5:54 AM
Post edited by FlayedOne (Novice) on Jan 27, 2010, 5:56 AM
Post edited by FlayedOne (Novice) on Jan 27, 2010, 5: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