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

Reading a file

P: n/a
Hello,

i'm new with perl.

I want to read a file and display this when visiting my website :

In my browser : http://www.website.nl/displayfile.pl
===================
#!/usr/local/bin/perl
$logurl = "/opt/guide/www.website.nl/log.txt";
# Begin the Editing of log File
print $logurl;
=====================
It doesn't work!!

Why?

Marco


Sep 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
In article <43***********************@text.nova.planet.nl>, Procor
<pr**********@newsprocor.news> wrote:
Hello,

i'm new with perl.

I want to read a file and display this when visiting my website :

In my browser : http://www.website.nl/displayfile.pl
===================
#!/usr/local/bin/perl
$logurl = "/opt/guide/www.website.nl/log.txt";
# Begin the Editing of log File
print $logurl;
=====================
It doesn't work!!

Why?


How does it not work?

You have to generate a complete HTTP response message, including the
appropriate headers. The easiest way to do that in Perl is to use the
CGI module and its header, start_html, and end_html subroutines.
Generating proper HTML for HTTP can be a complicated task, so you have
some studying to do. Start with 'perldoc CGI' for examples.

If you want to display the contents of a file, rather than just its
path name, you will have to open the file, read it, and print its lines
to the output. Look at Perl's open, print, and close functions, and the
'perldoc perlio' section of your online documentation.

FYI: the comp.lang.perl newsgroup is defunct. Try comp.lang.perl.misc
in the future or just stick with alt.perl.

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Sep 19 '05 #2

P: n/a
Procor wrote:
Hello,

i'm new with perl.

I want to read a file and display this when visiting my website :

In my browser : http://www.website.nl/displayfile.pl
===================
#!/usr/local/bin/perl
$logurl = "/opt/guide/www.website.nl/log.txt";
# Begin the Editing of log File
print $logurl;
=====================
It doesn't work!!
Hmmm, strange. By all means your program should print the verbatim text

/opt/guide/www.website.nl/log.txt

to STDOUT, usually your terminal.
And it does when I run your snippet on my computer.

C:\tmp>t.pl
/opt/guide/www.website.nl/log.txt
C:\tmp>

What do you expect the code snippet to do instead?
Why?


Unless you tell us what you expect this code snippet to do we cannot tell
what you did wrong because we don't know your goal.

jue
Sep 20 '05 #3

P: n/a

"Procor" <pr**********@newsprocor.news> wrote in message
news:43***********************@text.nova.planet.nl ...
Hello,

i'm new with perl.

I want to read a file and display this when visiting my website :

In my browser : http://www.website.nl/displayfile.pl
===================
#!/usr/local/bin/perl
$logurl = "/opt/guide/www.website.nl/log.txt";
# Begin the Editing of log File
print $logurl;
=====================
It doesn't work!!

Why?

Marco


# added -w (warn) I think you will need it
#!/usr/local/bin/perl -w

# ok you defined what file you want to view
$logurl = "/opt/guide/www.website.nl/log.txt";

# this actually opens the file for use and returns any errors
open (FILE, "$logurl") or die "Couldn't open $logurl: $!";.

# you will need to call each line of the file for use.
# $_ is what you will be working with.
# With each pass through the loop $_ will have the new line data.
while (<FILE>) {
print $_; # what you do with each line in here is up to you.
}

close (FILE); # be nice and close the file

Hope that helps,
Bill
Sep 28 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.