Gossamer Forum
Home : General : Perl Programming :

another quick question

Quote Reply
another quick question
I am trying to open a log file, store all the lines to an array, and then be able to print each line in the array. the problem is with the foreach. I was reading about it and I thought that I used it correctly but apparently not. I have never seen it before either so is this a real thing I can use or just a cruel joke . Wink

#!usr/local/bin/perl

open (USRLOG, "<usrlog.txt") or die "could not open log file";

@usrlist = <USRLOG>;

close USRLOG;

foreach $username (@usrlist) {
Print "$username";
}
------------------------------------------------------------
......and why not?
Quote Reply
Re: [A1R3S3F7R] another quick question In reply to
I don't see anything wrong with that script other than you capitalized the "p" in "print"... unless you are attempting to run it via the web. in that case you need to print a content type header.

for literal output (text files, etc.) use "Content-type: text/plain\n\n"
for html output use "Content-type: text/html\n\n"

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [A1R3S3F7R] another quick question In reply to
Use this:

Code:
open USRLOG, "usrlog.txt" or die "could not open log file: $!";
print while USRLOG;
close USRLOG;

Last edited by:

Paul: Nov 26, 2002, 2:38 AM