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!

Perl thinking that $ isn't Text

Status
Not open for further replies.

tbad1986

Technical User
Apr 1, 2002
24
0
0
US
I'm having trouble with my news script. Right now when I put a $ it thinks that it should have a value and then prints nothing. So if I put something like "the x costs $4.56" it only prints "the x costs" and that would be it.

If someone knows how to print a $ without it thinking that it would be a "value"

If you need the script I can e-mail it to you.
 
u might want to do this:

"the x costs \$4.35"
 
You need to escape the $ sign by adding a \ in front of it. This way the perl interpreter doesn't interpret the dollar sign as being a varible.

$var = "the x costs \$4.56";
print $var;
 
The $ is an input though. I get it from a form and I can't tell them to put a \ in front of it because I know someone won't do it and will mess it up.

Is there a way I can automatically add it if there is a $ in a form box?
 
$input =~ s/\$/\\$/g;

try that on the string.
 
Uhm, I'm sort of new at this.. where would I put that? Before it starts to print it (viewing the news) or when you click submit and it saves it?
 
Lets have a look at your current code and see if we can help!
 
.....
$input = $FORM{inputname}; # or your way to store in input
chomp $input;
$input =~ s/\$/\\$/g;
... someone knowledge ends where
someone else knowledge starts
 
Alright, but it's big :D (If you find something I could change to make it faster/cleaner please tell me, but try to stick to the problem I'm getting)

#!/usr/bin/perl

print "Content-type:text/html\n\n";
print &quot;<HTML>\n&quot;;
print &quot;<HEAD>\n&quot;;

require TripodCGI;
require TripodDate;

$CGI = new TripodCGI;
$DATE = new TripodDate;
$today = $DATE->currentDate();
$news = $CGI->param('news');
$pass = $CGI->param('pass');
$action = $CGI->param('action');

$graybg = '<style fprolloverstyle>A:hover {color: #FFFFFF}</style>'
.'<style><!--A{text-decoration:none}--></style>'
.'</head>'
.'<body text=&quot;#000000&quot; bgcolor=&quot;#C0C0C0&quot; link=&quot;#000000&quot; vlink=&quot;#000000&quot; alink=&quot;#000000&quot;>';
$whitebg = '<style fprolloverstyle>A:hover {color: #000000}</style>'
.'<style><!--A{text-decoration:none}--></style>'
.'</head>'
.'<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot; link=&quot;#666666&quot; vlink=&quot;#666666&quot; alink=&quot;#666666&quot;>';

my $webmaster = 'tbad1986@yahoo.com';
my $newsfile = 'file.txt';
my $SEPARATOR = &quot;Ð&quot;;

my %TRUSTED = (
I have this setup, but don't want people to see it.

#This is option 1A, posting news.
if ($action eq &quot;post&quot;) {

if ( $pass eq &quot;&quot; || $news eq &quot;&quot; ) {
errors( &quot;Sorry, but you left a field blank.&quot;,
&quot;Please press back on <b>your browser</b> and fill it in!&quot; );
}

elsif ( defined $TRUSTED{$pass} ) {

my $handle = $TRUSTED{$pass}->[0];
my $email = $TRUSTED{$pass}->[1];

open(OUTF, &quot;>>$newsfile&quot;)
or errors(&quot;Can't open database! Please contact the website admin!&quot;);

print OUTF join($SEPARATOR, $handle, $email, $news, $today), &quot;\n&quot;;
close (OUTF);

print <<End;
<title>news submitted</title>
$whitebg
<center><b>Your news has been submitted $handle</b><br><br><br>
<br><b>Date:</b> $today
<br><b>This was submitted:</b> $news
<br><br><br><a href=&quot;&quot;>Go Back to the Member's Page</a></center>
End
}

else {
errors( &quot;Sorry, but you do not seem to have the right password.&quot;,
&quot;If you're a member please contact MooMan to get a password&quot;);
}

}

#This is option 1B, viewing the news.
elsif ($action eq &quot;news&quot;) {

open(INF, $newsfile)
or errors(&quot;Sorry, but their was an error. Please contact the website admin!&quot;);
my @news = reverse( <INF> );
close INF;

print <<End;
<link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot; <title>news</title>
End

foreach $line (@news) {

($handle,$email,$news,$today) = split(m/$SEPARATOR/, $line);

print <<End;
$graybg
<center>
<table border=&quot;1&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse: collapse&quot; bordercolor=&quot;#111111&quot; width=&quot;100%&quot; id=&quot;AutoNumber4&quot; bgcolor=&quot;#666666&quot;>
<tr>
<td width=&quot;50%&quot; bordercolor=&quot;#666666&quot;>
<font color=&quot;#000000&quot;><small>posted by:</small> <a href=&quot;mailto:$email&quot;>$handle</a>
</font></td>
<td width=&quot;50%&quot; bordercolor=&quot;#666666&quot;>
<p align=&quot;right&quot;>
<font size=&quot;2&quot; color=&quot;#CCCCCC&quot;>$today</font></td>
</tr>
<tr>
<td width=&quot;100%&quot; colspan=&quot;2&quot; bgcolor=&quot;#FFFFFF&quot;>
<p align=&quot;center&quot;>$news</td>
</tr></center></table><br><br>
End

}
}

# Error Sub
sub errors {

my($error) = @_;

print <<Error;
<title>error</title>
$graybg
<center><h2>error</h2><br>$error<br></center></td>
Error
}

print <<End;
</table>
</body>
</html>
End
 
Shouldn't the replacement string be \\\$

Seems to me you need to escape the backslash and the dollar sign. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top