Solved

Why perl program output this ?

Posted on 2003-10-26
3
245 Views
Last Modified: 2010-03-05
Hi,

I've written below perl program for testing in my web site hosted in one ISP.

Source code below:

#!/usr/bin/perl

$a = "Hello!";
print "Content-type: text/html\n\n";
print "<html>\n<head>\n";
print "</head>\n<body>\n";

$e = "<xxxx>";
$e =~ s/<//;
print "variable e = $e<br>";
$e =~ s/>//;
print "variable e = $e<br>";

$f = "<xxxx>";
$f =~ s/>//;
print "variable f = $f<br>";
$f =~ s/<//;
print "variable f = $f<br>";

print "</body>\n</html>";

Output of the program at browser is as follow:

variable e = xxxx>
variable e = xxxx
variable f = variable f = xxxx

Why will 2 distnct print statements for $f will result in only one output line ? Why the second print statement seems overwriting the first ? Is there any meaning to character '<' if it appears alone in a " " quoted string i.e. "<xxxx" ?

0
Comment
Question by:lonelyplanet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 10

Accepted Solution

by:
rj2 earned 100 total points
ID: 9623474
Replace lines "$f =~ s/>//" and "$f =~ s/<//" with line below.
$f =~ s/[<>]//g;

This happen because when there is a starting < browser interpret that as a start tag, and when the <br> comes it is ignored because there can't be any nested tags.
0
 
LVL 8

Assisted Solution

by:jhurst
jhurst earned 25 total points
ID: 9675994
&lt; is the correct way of outputting a < to an html screen!
0
 
LVL 20

Expert Comment

by:jmcg
ID: 10038148
Nothing has happened on this question in over 2 months. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
split points between rj2 [100 ptt] and jhurst [25 pts].

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question