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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filehandle error - rookie needs help!

Status
Not open for further replies.

NewBoy

ISP
Mar 8, 2001
20
0
0
GB
Hi,

I am trying to understand Filehandles properly. I don't really want to know an easier/alternative way of doing this. Instead, I'd like to know why this isn't working. The name of the script file is test_filehandle.

I get the error:

SERVER:~$ test_filehandle
syntax error at ./test_filehandle line 5, near &quot;while <ISDNLOG>&quot;
Execution of ./test_filehandle aborted due to compilation errors.

This is the script:

Code:
SERVER:~$ cat test_filehandle 
#!/usr/bin/perl -w

open (ISDNLOG, '/home/cnew/detail_short.20010805') or die &quot;Unable to open ISDNLOG\n\n&quot;; #[open log file]

while <ISDNLOG>

        {
        if (/\w/) 
                {
                print $_;
                }
        }

close ISDNLOG;

I thought it would work as follows: Open the file, and call it ISDNLOG. For each line in ISDNLOG, if the line begins with a word-character, print the line. Close ISDNLOG.

Help appreciated!
 
Hi everyone,

Realised my mistake about 5 mins after posting my original enquiry.

In case anyone didn't know (though I doubt this is the case...) I was missing parentheses around the while condition, i.e.:
Code:
while (<ISDNLOG>)

Sorry to post something so trivial!

C.
 
you posted the answer as well :) and you can bet you're not the only person to try it that way..... (not me, of course :)) Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top