John W.Krahn <[EMAIL PROTECTED]> writes:

> On Tuesday 11 December 2007 14:09, [EMAIL PROTECTED] wrote:
>>
>> John W.Krahn <[EMAIL PROTECTED]> writes:
>> >
>> > use Fcntl ':seek';
>> >
>> > seek FILE, -100, SEEK_END or die "Cannot seek on './myfile' $!";
>>
>> Still seeing something I don't understand.  Using a working version
>> of the code I posted (included at the end) telling seek to go to 100
>> bytes before the byte count at eof.  I see a small discrepancy in
>> where it actually goes of 5-15 bytes.
>>
>> I didn't use Fcntl ':seek' because it appears to lack the other two
>> operators (SEEK_SET, SEEK_CUR) referred to at perldoc -f seek.
>
> perldoc Fcntl
> [ SNIP ]
>        For ease of use also the SEEK_* constants (for seek() and
>        sysseek(), e.g. SEEK_END) and the S_I* constants (for
>        chmod() and stat()) are available for import.  They can be
>        imported either separately or using the tags `:seek' and
>        `:mode'.

As you've no doubt noticed, I'm not the brightest bulb on the tree. I
didn't really understand what that meant until your insistence it was
available.  Even now I'm not sure what is meant by `imported
separately or using the tags :seek and :mode to import.  Apparently
some other syntax I have yet to try.... I'll experiment until I get
that right later, but using: `

   use Fcntl :seek;

fails if either SEEK_SET or SEEK_CUR are used in seek().  Whereas it
works as expected if SEEK_END is put into seek();

>> And it seems like what I really needed was SEEK_SET or (zero 0) as
>> shown at perldoc -f seek.  Since using SEEK_END or (2) will give an
>> unpredictable seeking location because the amount of data entered
>> will vary every time (a real working version) of this script gets
>> used.

>> So subtracting the original end of file byte cnt + 100 may not go
>> where we want to be.  Seems like it would be better to tell seek to
>> go to 100 bytes before the original end of file byte count. So I had
>> that wrong originally too.

Above paragraph  includes a typo... might have led to some confusion.

It should have said  "So subtracting the CURRENT ....."
instead of           "So subtracting the original ....."

Because the seek comes after more data is inserted into FILE
eof of `current' will be a larger count than eof of `original' making
SEEK_END a bad choice.


>> That is what I'm attempting here but as mentioned above it appears to
>> show an additional offset of 12 bytes from somewhere:  OS?
>> Im running Gentoo linux,
>
> I am not sure your example proves what you seem to think it is trying 

That is a very likely state.

> to prove and as you have not provided the contents of "myfile" I cannot 
> run your example but I can see no discrepances in the code you posted.

But you can see in the code and results that the eof (or first) byte
count reported is smaller than the next one reported once the while
loop starts.   

You always ask such good questions they often make me find the
mistake.  That has happened here just now. As I typed the above
sentence it dawned on me that after the while loop starts the byte
count reported will include the current line so it will be a bit
larger than where seek(FILE, ($bytes - 100) ,0); started it.

> What exactly were you expecting it to do that it did not do?  Or not do 
> that you expected it to do?

I expected it to seek to the byte count reported at end of file and
now I see that is exactly what it is doing.... thanks.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to