Next | Lightweight Databases | 32 |
This looks innocuous, but it opens a 55-gallon drum of worms:
seek $fh, -length($_), SEEK_CUR;
Here we wanted to back up to the beginning of the current record
This won't always work
Seek positions don't always correspond to character offsets
Consider a DOS file:
I like pie\r\n Especially apple.\r\n
After reading the first record, tell is likely to return 12
But $_ will contain "I like pie\n" (11 characters)
The \r\n is translated to just \n on input
The problem gets much worse with variable-length character encodings like UTF-8
Next | Copyright © 2003 M. J. Dominus |