On Dec 11, 1:22 pm, [EMAIL PROTECTED] wrote:
> Using perldoc -q tail
> leading to
> perldoc -f seek
> perldoc -f tell
>
> I'm not getting how to use those functions.
There's a lot of things you're not getting, actually...
> 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.
for( ; ; ) { }
is an infinite loop, as there is no condition telling the loop when to
end. It's no different than
while (1) { }
> This stuff is supposed to be
> readable by someone who doesn't know these things.
The hell it is. You want the documentation for seek() to explain to
you how a for loop works? Go read the documentation for 'for' if you
don't understand it. The documentation for seek() need only be
readable to people who don't know seek() works.
> 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.
Well, gee, since the point of these functions is to seek to a position
in a file, and to tell you what the current position of a file is, is
it really that much of a leap to think that "curpos" might stand for
"current position"? Nevertheless, if you think that's a problem, no
one's stopping you from submitting a documentation bug fix, using
perlbug.
> However, I still don't see how it is supposed to work. Is there a law
> against simple examples? hehe.
> (ok enough complaining ...)
More than enough, actually. You passed "complaining" and entered
"whining" quite a while ago.
> 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);
This has absolutely nothing to do with you not understanding seek()
and tell(), but rather you not understanding open(). You've opened a
file for appending, and then you're trying to read from that
filehandle. You can't do that.
Read
perldoc -f open
for how to open a file in read/write mode.
Paul Lalli
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/