some basic perl questions

Posted on 2004-04-11
Last Modified: 2008-02-20
 I am working on a code created by someone else in perl.
Since I am new to perl, I coudln't understand few things
in the program(though the program works perfectly)

1) For every function being called in the program the first print statement is
repeated twice , but in the output only one of the statement is printed. I tried
to remove one of the print statement, but the other print statement also doesn't
print, looks strange and weard, but I dont understand the reasoning behind it.

2) The program is called from the web url like

It works perfectly when given input from the url, but when I tried
to execute it from Unix prompt by calling
perl input1=something&input2=something&input3=something

except for the first input rest are not assigned. Since I am new
to perl I believe it could be because of the param function being used.

like the function calls a CGI at first
$a = new CGI;

I assume that the program supports only input throught URL(CGI mode) or
I am giving in the inputformat in a wrong way.

3) When the program is called it executed properly, but the IE screen is blank, in
order to view the output I have to look into view source, which has the proper output.
Is there a way to print the output on screen itself, I mean on the Internet Explorer.

Question by:shanky1978

Expert Comment

ID: 10803073
post the program here
LVL 20

Accepted Solution

jmcg earned 125 total points
ID: 10803283
Even if you cannot post the entire script (do not post it if it bears copyright notices or if it is proprietary software), you could post a couple of lines giving an example of the first part of your question, the part relating to print statements.

Programs using the CGI module can be run from the command line but you need to be careful how you set them up for accepting their input. The shell syntax is sensitive to some of the characters, such as "&", so without quotes or other suitable treatment, the shell will split that line you showed into three separate commands. Thus:

   perl "input1=something&input2=something&input3=something"

would probably work.

There are a number of conditions that would cause IE to display a blank page even though the page contained something. It sounds as if there may be some malformed HTML being output, but without seeing a sample, I'm afraid I'm just guessing.
LVL 84

Expert Comment

ID: 10803383
You can call it from the command line as
perl input1=something input2=something input3=something

(to unix command shells, & means to run processes simultaneously)
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center


Author Comment

ID: 10805986
 Thanks. I tried passing the input as you said and it does work. I am attaching the sample of the code, for the print statement issue. I am new to perl, but the logic here is really simple and still I dont understand why there are two print statements.

sub output
  my @args=@_;
  my $first = shift(@args);

 print"<first line of the output>\n";
# (this statement is ignored, it doesn't get printed but if i remove this line first line inside
# the if statement doesn't get printed)
 if ($first !~/^1.0$/)
        print"<first line of the output>\n";
        print "<second line of the output>\n";
        print "<third line of the output>\n";

#(Similarly in the following 2 lines only one of them is printed, if i remove or comment one of them
# the first line doesn't get printed)
          print"<first line of the output>\n";
        print"<first line of the output>\n";
        print "<second line of the output>\n";
        print "<third line of the output>\n";

LVL 20

Expert Comment

ID: 10806948
That's certainly peculiar, but I can't help thinking that your extraction of the examples has left out some vital clue. When I try this code with the version of Perl that I'm running here, every print statement works normally; no lines are missing.

You're working in a CGI context, right? At what point is the content-type header being printed? That would be one way for a line of printing to go missing -- if it were seen by the browser as part of the header. That might also be consistent with the other problem you mentioned, of IE displaying a blank page, which it may do because the HTML is incorrectly laid out.

Author Comment

ID: 10807955
  Again thanks a lot , as u have mentioned the content type tag was commented(it had an # in front of it) and once I removed thats it started working normally. I think the previous programmer would have missed to see that # in front of the content type tag(infact even I had missed it, only aftet you mentioned  I noticed it). Once it was fixed both the print problem as well as the one in IE was solved.

Thanks .



Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (…
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…

808 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