in reply to RE: current array index
in thread current array index

__LINE__ would give me the line numb er of current program, what I want is the index of the array which I am spooling out to a file, i.e. what it's line number _will be_ when it gets there so I can add that line number to any line containing an error trap so the error trap spits out the line it's on.

I just read up on caller and i don't get it : ) I'm gonna play with it and see what I get...

thanks!

"sometimes when you make a request for the head you don't
want the big, fat body...don't you go snickering."
                                         -- Nathan Torkington UoP2K a.k.a gnat

Replies are listed 'Best First'.
(tye)RE: current array index
by tye (Sage) on Nov 04, 2000 at 00:26 UTC

    If you put a literal __LINE__ in the output (but not inside quotes), then it will be replaced with the line number of the output file, which appears to be what you want. For example, your final output would look like:

    dienice("Line ",__LINE__,": oops\n");

    Alternately, you could use caller inside your dienice() routine. It would give you the line number of where dienice() was called from so you could prepend it to the message and wouldn't have to rewrite the calls to dienice(). For example:

    sub dienice { my $line= (caller)[2]; dienicely( "Line $line: ", @_ ); }

            - tye (but my friends call me "Tye")
      Exactly.

      AHHH! now I see what was meant... silly me.

      caller makes sense now too.

      Man. you guys rule. I learn from books, but sometimes I miss things like this until people show me - it's just the way I learn. Thanks so much.

      "sometimes when you make a request for the head you don't
      want the big, fat body...don't you go snickering."
                                               -- Nathan Torkington UoP2K a.k.a gnat