[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Search::Dict?



Richard Gordon wrote:
> 
> On 2/11/1999 at 21:59, rjk@linguist.dartmouth.edu (Ronald J. Kimball) wrote:
> 
> > According to the documentation for Search::Dict (you did read the
> > documentation, right?):
> > 
> Sure, as well as the Camel comments, but I didn't notice the * in *FILEHANDLE
> originally. I also now notice that the docs describe the variables as I<$x> and
> wonder what the leading I signifies?
> 

Try looking at the documentation with Shuck.  :-)

I<> is pod for italic.  C<> is code, E<> is emphasis, L<> is link, etc.
The <> is part of the pod, *not* part of the Perl code.

> >   Sets file position in FILEHANDLE to be first line greater than or equal
> >   (stringwise) to $key.  Returns the new file position, or -1 if an error
> >   occurs.
> > 
> > First, look() sets the *file position*.  In other words, it does a seek to
> > the beginning of the line; this has nothing to do with $..
> >
> Okay, but doesn't this necessarily mean that the last line read has to be the
> one that I'm after? Otherwise, how does it know what the position is?
> 

Ah, I see what you mean...  That depends entirely on the implementation of
look().  Looking at the code, I see a lot of seek()s, and a lot of reads
from <FH>, including one that is labeled "# probably a partial line".  Note
that every successful <FH> call increments $., regardless of whether the
input returned was a "complete" line, and regardless of whether that
particular input was already read in before a seek() back in the file.

Thus, I don't think you can rely on the value of $. from look().

> > Second, if there is an error, look() returns -1, which is a *true* value.
> > This is why your conditional succeeded even though the look() failed.  Test
> > that the return value is >= to 0 instead.
> 
> If a negative result is true and that's what this returns on error then it will
> be true no matter what if you just evaluate true/false? Good God. Originally, I
> was testing for > -1 and then changed it to simple true/false in the course of
> trying to get it to work. Thanks for the explanation.
> 

Actually, it won't be true no matter what.  If the target is found on the
first line, then look() returns a file position of 0, which is false.  :)
So, check that the return value is greater than or equal to 0.

Ronald

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch