Solved

Why perl program output this ?

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

816 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

8 Experts available now in Live!

Get 1:1 Help Now