Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open file

Status
Not open for further replies.

perln00b

Programmer
Oct 4, 2005
21
US
I tried to create a simple script to open a file,
and I always got this error msg,

"Use of uninitialized value in concatenation (.) or string at readfile.pl line 5.
readline() on closed filehandle LOG at readfile.pl line 7."

Here is my code:
###########################################################
open(LOG, "< $_");
@log = <LOG>;
foreach $line (@log)
{
print $line;
}
##########################################################
And I passed a file to the script:
C:>perl readfile.pl foo.log

Please help me.

thanks
lucas
 
You don't need to open the file at all.
Perl will do it for you:
Code:
#!/usr/bin/perl -w
use strict;
while(<>) {
  print;
}
I could have shortened this to one line but I'm sure your code is merely a starting point for you so I left it as usable as possible. Each line of the log file will appear in $_ in turn within the while loop so do you line-by-ilne processing there.


Trojan.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top