Solved

some basic perl questions

Posted on 2004-04-11
6
207 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
0
Comment
Question by:shanky1978
6 Comments
 
LVL 3

Expert Comment

by:prady_21
ID: 10803073
post the program here
0
 
LVL 20

Accepted Solution

by:
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 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
 
LVL 84

Expert Comment

by:ozo
ID: 10803383
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:shanky1978
ID: 10805986
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
 
LVL 20

Expert Comment

by:jmcg
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.
0
 

Author Comment

by:shanky1978
ID: 10807955
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

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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 …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

708 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

15 Experts available now in Live!

Get 1:1 Help Now