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

Re: [MacPerl] Search::Dict?



Richard Gordon wrote:
> 
> if (look <F>, $key, $dict, $fold)  {
> $line_number = $.;

<F> is in list context, so you read in the entire file and pass it to
look().

Then you set $line_number to $.; you just read in the entire, so the number
is $. is the last line in the file.


According to the documentation for Search::Dict (you did read the
documentation, right?):

  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 $..

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.

Hope that helps!

Ronald

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