- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Another Perl CGI Question
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-02-2002 08:13 AM
тАО08-02-2002 08:13 AM
#!/opt/perl/bin/perl
$inx=0;
open ONCALL, ("/usr/local/apache/cgi-bin/unixoncall.txt" or die "Counld not open file!\n");
while (
chomp;
@oncall[$inx]="$_";
$inx++;
}
print "Content-type:text/html\n\n";
print "
print "
$oncall[1]
";
print "";
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-02-2002 08:18 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-02-2002 08:40 AM
тАО08-02-2002 08:40 AM
Re: Another Perl CGI Question
Thanks,
Jason
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-02-2002 09:29 AM
тАО08-02-2002 09:29 AM
Re: Another Perl CGI Question
open (ONCALL, "/usr/local/apache/cgi-bin/unixoncall.txt") or
die "Counld not open file!\n";
As you've written it, if open() fails the script continues
to execute. The die() only gets called if the filename is
not true.
Also, your use of:
@oncall[$inx]="$_";
should probably be:
$oncall[$inx]="$_";
Also note that Perl array indices (normally) start at zero
and not one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-05-2002 11:10 PM
тАО08-05-2002 11:10 PM
Re: Another Perl CGI Question
Gregory is absolutely right.
Your code exhibits some obscurities, which I think are only due to some unfamiliarity with Perl.
First your open() call is strange indeed, but works because open() also accepts a list after its first argument which is a filehandle. (please read the open() POD, viz. "perldoc -f open").
The round parentheses depict a list, which in your case has as its only element the path to unixconcall.txt.
Since your or'ed the path string (which is always defined) to a die() call that never will be executed, your list has only this one element which is a valid filename.
Thus the Perl compiler won't complain even if you ran it with warnings enabled.
You have to choices.
Either you omit the parentheses altogether (which is a bit more like the sloppy Perlish style)
e.g.
open ONCALL, '/usr/local/apache/cgi-bin/unixoncall.txt'
or die "cannot open: $!\n";
or (as preferred by people coming from more strict languages), you embrace the two arguments with a pair of parentheses
e.g.
open(ONCALL, '/usr/local/apache/cgi-bin/unixoncall.txt')
Then the assignment
@oncall[$inx]="$_";
actually is an assignment to a slice.
I really don't believe that you indended this, because it doesn't make much sense in this context.
Remember, Perl basically distinguishes between two "types", either list or scalar context.
Whenever you reference a single element of an array you address it in scalar context, thus requiring the '$'
$oncall[$inx] = "$_";
Apart from this, if you really afford to squeeze the whole file in an array you can have this much easier by enforcing list context with the diamond operator
e.g.
@oncall =
However, this is not very resource efficient, and you should rather loop through the lines of a file.
If you mean to address the first element of a list, you will have to use the index 0 unless you redefined the special Perl variable '$[' (which is really deprecated)
Read the POD "perldoc perlvar".
As far as CGI is concerned you'd better use the CGI.pm module (which is easier and *safer*)
Read "perldoc CGI".
For tampering with files also read
"perldoc perlopentut"
And finally, I'd strongly recommend to read the following:
"perldoc perldata"
"perldoc perlsyn"