We help IT Professionals succeed at work.

some basic perl questions

shanky1978
shanky1978 asked
on
237 Views
Last Modified: 2008-02-20
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
Comment
Watch Question

Commented:
post the program here
Owner
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

Commented:
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)

Author

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
jmcgOwner

Commented:
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

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


Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.