Newsgroups: comp.lang.awk
From: arn...@skeeve.com (Aharon Robbins)
Date: Thu, 22 Jan 2009 05:28:47 +0000 (UTC)
Local: Thurs, Jan 22 2009 12:28 am
Subject: Re: More on BEGINFILE / ENDFILE
In article <gl6qdb$kb...@heraldo.rediris.es>,
Manuel Collado <m.coll...@invalid.domain> wrote: >> Um, I don't know what you're referring to here: Ah. Well, this goes back to the fact that command-line filenames are fatal >> $ gawk-3.1.6 'BEGIN { print (getline x < "/no/file") }' >> Am I missing someting? >I was speaking about non-redirected getline: >$ gawk 'BEGIN { print getline x }' /no/file errors when they can't be opened. It is historical practice and consitent with the other awks: $ mawk 'BEGIN { print getline x; print 1 }' /no/file $ nawk 'BEGIN { print getline x; print 1 }' /no/file I understand your point, but I worry that it is too big a break with >>> Please also consider that ENDFILE is an appropriate place to catch That works nows; you should then add a nextfile to skip the bad file. >>> errors while reading records. >> What kind of errors show up while reading records that are catchable? >I wonder if the following code could be used to test for readability of >BEGINFILE { >ENDFILE { I don't think anything would ever get here; If the file cannot be opened > if (ERRNO) { > print "error reading " FILENAME " after line " FNR ": " ERRNO > } >} or is a directory, you catch it in the BEGINFILE block. If the file was already successfully opened, and if, say, an NFS file >Same by using getline alone: (Your loop, BTW, checks the file's readability for every record read; >BEGIN { not very efficient.) The gawk manual shows you how to do this by simply looping through ARGV, >If input errors are not flagged as fatal, the above examples will I understand, but I think the current BEGINFILE semantics give you >process all arguments, even some of them are unreadable. the hooks to handle things adequately. Thanks, Arnold You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||