Solved

Why perl program output this ?

Posted on 2003-10-26
3
202 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
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now