It's easy enough to get the current size of the file:
my $current_file_size = -s $file_name;
So you just need to have that value, and check it against the number that the user provides as the offset to go to:
if ( $start_pc >= $current_file_size ) { warn sprintf( "Your requested offset (%d) is past EOF (%d)\n", $start_pc, $current_file_size ); # and do something else, like prompt for new input }
Of course, if the user is asking for fixed-length-record $n, you'd want to say that the requested $n is greater than the number of records in the file (file size divided by record size, which, in an ideal world, would always be an integer value).

In reply to Re: seek function always returns true by graff
in thread seek function always returns true by rudyg123

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.