in reply to seek function always returns true

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

Replies are listed 'Best First'.
Re^2: seek function always returns true
by rudyg123 (Initiate) on Jun 20, 2007 at 14:10 UTC
    Thanks for all who responded to my question. I didn't realize how seek actually worked until you guys posted these responses. I didn't know that seek() could actually go beyond the EOF. I tried the code that you guys provided and it worked for me. The key for me was doing the read(). If you try and read past the EOF you do get an error. RG