• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 220
  • Last Modified:

some basic perl questions

Hi,
 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
complete_path/program.pl?input1=something&input2=something&input3=something

It works perfectly when given input from the url, but when I tried
to execute it from Unix prompt by calling
perl program.pl 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;
foreach($a->param)


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.

Shankar
0
shanky1978
Asked:
shanky1978
1 Solution
 
prady_21Commented:
post the program here
0
 
jmcgOwnerCommented:
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 program.pl "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.
0
 
ozoCommented:
You can call it from the command line as
perl program.pl input1=something input2=something input3=something

(to unix command shells, & means to run processes simultaneously)
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
shanky1978Author Commented:
Hi,
 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";
        return;
       }

#(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";
        return;
}

Shankar
0
 
jmcgOwnerCommented:
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.
0
 
shanky1978Author Commented:
Hi,
  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 .

Shankar


0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now