i hope i can clarify what whence means:
snip
For WHENCE you may use the constants "SEEK_SET", "SEEK_CUR", and
"SEEK_END" (start of the file, current position, end of the file)
from the Fcntl module.
snip
whence descripes from where you start counting bytes:
if you use "SEEK_SET" (start of the file) and you jump to
seek(FH, 10, 0)
youll jump to the 10th byte from the beginning of the file.
if you now do SEEK_CUR
seek(FH, 5, 1);
youll jump to the 15th byte.
if your file is 100bytes large, and youll do a
seek(FH, 1, 2)
youll jump the the byte before the end of the file.
HTH
On Tue, 11 Dec 2007 12:22:18 -0600
[EMAIL PROTECTED] wrote:
> Using perldoc -q tail
> leading to
> perldoc -f seek
> perldoc -f tell
>
> I'm not getting how to use those functions. Partly because what
> passes for examples in those docs doesn't use normal language, instead
> they use terms like WHENCE, something that's almost never used in
> normal language. When WHERE would get the point across at a glance
> instead of having to dig into the details,
>
> At first I took it to mean something more involved than giving a
> possition.
> No biggee I guess but then I see:
>
> for (;;) {
> for ($curpos = tell(FILE); $_ = <FILE>;
> $curpos = tell(FILE)) {
> # search for some stuff and put it into files
> }
> sleep($for_a_while);
> seek(FILE, $curpos, 0);
> }
>
> Even here what the heck does `;;' mean. This stuff is supposed to be
> readable by someone who doesn't know these things. Even down to
> `curpos'. I didn't get what it meant for a few seconds. Why not
> spell it out... $CurrentPostion. After all clarity is what we're
> after here.
>
> Again no biggee I guess,
>
> However, I still don't see how it is supposed to work. Is there a law
> against simple examples? hehe.
> (ok enough complaining ...)
>
> seek documentation indicates the for loop probably won't be necessary
> unless the IO implementation is `particularly cantankerous'. So I'm
> guessing there is some easier way to access the stuff below where I've
> told the interpreter to seek to.
>
> It left me thinking something like this should work but it absolutely
> fails to print tell() from seek(FILE, -($bytes -100) ,2) position.
>
> use strict;
> use warnings;
>
> my $bytes;
> open(FILE,">>./myfile")or die " Can't open ./myfile: $!";
> $bytes = tell(FILE);
> print "hpdb pre seek bytes <$bytes> \n";
> print FILE "line\nline\nline\nline\n";
>
> ## go back to 100 bytes before previous end of file.
> seek(FILE, -($bytes -100) ,2);
> while(<FILE>){
> print "hpdb tell by line:" . tell(FILE) . "\n";
> }
> close(FILE);
>
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/