Hi Monks, my first post here; I've been lurking for some time, ever since I became a perl coder. I ran across something interesting today in the behavior of seek on a tied filehandle that I could not find in any documention or discussion on this wonderful site. A little background: I wrote a tied filehandle module to return records of binary science data. The records are indexed by time, so my SEEK function naturally accepts a time value; a *floating-point* time value: since the data are accumulated on millisecond scales. But things were not right; the seeks went awry. Why?

Because 'seek' is a perl function that magically accesses my own SEEK subroutine, but which *always* coerces its second argument (the first is the fh) to an integer! Do you doubt this? See the code below!

(btw: I fixed my little problem by multiplying the times in the argument list by 1000 and then dividing by same within SEEK.)

- GRR
#!/usr/bin/perl use strict; package myNull; sub TIEHANDLE { my $class = shift; my $fh = local *FH; bless \$fh, $class; } sub SEEK { my $class = shift; my $offset = shift; my $whence = shift; print "SEEK: offset = $offset\n"; } 1; perl -e 'use myNull; tie *null, "myNull"; seek null, 5.5, 0;' SEEK: offset = 5

In reply to Interesting SEEK behavior on tied filehandle by GammaRay Rob

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.