Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: Question ab...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 7 of 7 Topic 2167 of 2317
Post > Topic >>

Re: Question about a programme

by Spiros Bousbouras <spibou@[EMAIL PROTECTED] > Feb 19, 2008 at 11:49 AM

On Feb 18, 3:38=A0pm, Janis <janis_papanag...@[EMAIL PROTECTED]
> wrote:
> On 18 Feb., 15:14, Ed Morton <mor...@[EMAIL PROTECTED]
> wrote:
>
>
>
>
>
> > On 2/18/2008 6:57 AM, Spiros Bousbouras wrote:
>
> > > On page 194 of "Effective AWK programming" we see the
> > > following programme:
>
> > > # rewind.awk --- rewind the current file and start over
> > > function rewind( =A0 =A0i)
> > > {
> > > =A0 =A0 # ****ft remaining arguments up
> > > =A0 =A0 for (i =3D ARGC; i > ARGIND; i--)
> > > =A0 =A0 =A0 =A0 ARGV[i] =3D ARGV[i-1]
> > > =A0 =A0 # make sure gawk knows to keep going
> > > =A0 =A0 ARGC++
> > > =A0 =A0 # make current file next to get done
> > > =A0 =A0 ARGV[ARGIND+1] =3D FILENAME
> > > =A0 =A0 # do it
> > > =A0 =A0 nextfile
> > > }
>
> > > Isn't the statement ARGV[ARGIND+1] =3D FILENAME
> > > superfluous ? In the loop when i gets the
> > > value ARGIND + 1 then the assignment
> > > ARGV[ARGIND + 1] =3D ARGV[ARGIND] will be executed
> > > and ARGV[ARGIND] always has the same value as
> > > FILENAME
>
> > But what if the current file is the last one? Then i =3D ARGC =3D
ARGIND=
 at the
> > start of the loop, so the loop's never entered so THEN that final
assign=
ment is
> > required. Although that works in this context since the functiona name
i=
mplies
> > it MUST be called while parsing a file, use of FILENAME meanse you
can't=
 execute
> > this type of general "****ft the arguments" function in a BEGIN section
s=
o I'm
> > not a big fan.
>
> While filename is just unset in the BEGIN block it seems there's a
> more fatal problem with 'nextfile' in rewind()...
>
> $ xgawk 'BEGIN{nextfile}'
> xgawk: error: `nextfile' used in BEGIN action
>
> Note: I've just xgawk at hand but suppose that error is inherited
> from gawk.

Calling rewind() in BEGIN is meaningless so it's
a good thing that you get an error message IMO.
 




 7 Posts in Topic:
Question about a programme
Spiros Bousbouras <spi  2008-02-18 04:57:46 
Re: Question about a programme
Ed Morton <morton@[EMA  2008-02-18 08:14:15 
Re: Question about a programme
Janis <janis_papanagno  2008-02-18 07:38:59 
Re: Question about a programme
Ed Morton <morton@[EMA  2008-02-18 19:23:58 
Re: Question about a programme
Spiros Bousbouras <spi  2008-02-19 11:46:57 
Re: Question about a programme
Ed Morton <morton@[EMA  2008-02-19 14:05:50 
Re: Question about a programme
Spiros Bousbouras <spi  2008-02-19 11:49:55 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 14:59:59 CDT 2008.