By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,903 Members | 1,081 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,903 IT Pros & Developers. It's quick & easy.

Issues reading a simple text file

P: 2
Hi,

Thank you in advance for your help.

I am new to PERL, just a couple of days, but reading a lot. I found your site very exciting and informative.

I am trying to read a text file with a key 10 to 120 numbers in a single lime into an array. But I am getting a 500 error and do't know exactly what is the error. I am confused on how to make the code read from my web server (the path).
Perhaps my approach is incorrect!.

my code is as follows:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2. # readtext.pl
  3.  
  4. use strict;
  5. use CGI ':standard';
  6.  
  7. $filename = "//mypage.com/key.txt";
  8.  
  9. open (filename) || die "Couldn't open $filename: $!n";
  10. my @params=<filename>;
  11.  
  12. print
  13.        header(),
  14.        start_html(
  15.             -title => 'Welcome!',
  16.             -text  => '#520063'
  17.             ),
  18.             h1("the key is: $@params"),
  19.             end_html();
  20. ]
Thanks again

Tony
Mar 31 '10 #1

✓ answered by RonB

Add these use statements.
Expand|Select|Wrap|Line Numbers
  1. use warnings;
  2. use CGI::Carp qw(fatalsToBrowser);
Remove the -w switch

Lines 7 and 9 have problems which should become apparent after adding the use statements.

Line 18 also has a problem, but lets start with the more important issues.

Share this Question
Share on Google+
3 Replies


Expert Mod 100+
P: 589
Add these use statements.
Expand|Select|Wrap|Line Numbers
  1. use warnings;
  2. use CGI::Carp qw(fatalsToBrowser);
Remove the -w switch

Lines 7 and 9 have problems which should become apparent after adding the use statements.

Line 18 also has a problem, but lets start with the more important issues.
Mar 31 '10 #2

P: 2
Ron,

Thank you for your fast response, and comments.

I am still confuse on how to address the path for files under my web server. Could you please recommend any book or web page to read.

I am getting the following error after entering the two lines you suggested. Please see my code and error code as follows:

Error:
open //bcomputingcom.ipage.com/cgi-bin/key.txt: No such file or directory at /home/users/web/b1789/ipg.bcomputingcom/cgi-bin/readtext.pl line 12.

#!/usr/bin/perl
# readtext.pl

use strict;
use CGI ':standard';
use warnings;

use CGI::Carp qw(fatalsToBrowser);

my $inFile = "//bcomputingcom.ipage.com/cgi-bin/key.txt";

open(IN, $inFile) or die "open $inFile: $!";
my $line=<IN>;

print
header(),
start_html(
-title => 'Welcome!',
-text => '#520063'
),
h1("the key is: $line"),
end_html();
Apr 1 '10 #3

Expert Mod 100+
P: 589
The open function expects a relative or absolute system path, not a url or unc path. The path you're using is not a system path.
Apr 1 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.