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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I change this character " to ' ?

Status
Not open for further replies.

calormierda16

Programmer
Nov 13, 2004
5
0
0
US
I am trying to send HTML emails from Perl. The quotation marks are giving me trouble. Since HTML works without quotations or with this ('), how can I have a subroutine go through a flat file or variable and delete all the quotations?

Examples. <p align="right"> is no good
It works like this however <p align='right'> or <p align=right>

The reason why I ask this is I am making a mailing list program for my brother and I would like him to simply copy and past HTML code from Frontpage into the text area. It would be too confusing for him, and tedious, to explain to him why the quotes have to be removed, etc.

If there are any suggestions, I would love to hear them!
Thanks, Nick
 
i tried $string =~ s/\"/\'/g; but it doesn't work.
I also tried $string =~ tr/\"/\'/d; and that doesn't work.

Its just funny how every text editor has this option to seach for " and replace it with '. I can't seem to figure out how to make it work.
 
Code:
#!/usr/bin/perl

use warnings;
use strict;

my $string = qq(<p align="right">);

$string =~ s/"/'/g;

print $string;

Yields
Code:
<p align='right'>
 
I tried that code cgilover, and for some reason it doesn't work. I think you definetaly have to put a backslash in front of the characters " and '. Even when I do, it doesn't work.

 
cgilover's code works fine for me calormierda16

Mike

To err is human, but to really foul things up you need a man; women just don't have the flair for it.

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

 
This code definitly works on my system and MikeLacey says it works on his.

I don't know why it doensn't work on yours, even if you have an extremely outdated Perl package it should work. Maybe you need to reinstall Perl? That's the only solution I can come up with without knowing what the real problem is.

And nope, you don't have to slash " or ' as neither are special characters in regexes.
 
thats weird... I have copy and pasted your direct code into an editor, saved it as "test.cgi", uploaded it, set permissions to 755, and it says there is an Internal server error.

The joy of coding :)
 
I can tell you right now exactly what the error is. It's a premature end of script headers. This wasn't meant to be a CGI script but instead just Perl.

Try using this one on your website instead.

Code:
#!/usr/bin/perl

use warnings;
use strict;

use CGI qw/:standard/;

print header, start_html("test print");

my $string = qq(<p align="right">);

$string =~ s/"/'/g;

print $string;
 
Thanks a lot cgilover. You've been a big help and I appreciate it.
 
It's so important to set, and understand, CONTEXT, probably the most misunderstood word in the upper case alphabet, let alone language

EZ 4 Me 2 say, I've just had eight beers, but I'm right ...
--Paul

Nancy Griffith - songstress extraordinaire,
and composer of the snipers anthem "From a distance ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top