Thread Sysopen in Kombination mit seek/sysseek und print (12 answers)
Opened by Gast at 2007-06-25 11:09

bloonix
 2007-06-26 15:04
#77798 #77798
User since
2005-12-17
1615 Artikel
HausmeisterIn
[Homepage]
user image
Okay... ein wenig Nachforschung bringt die Antwort...

file.txt hat eine Größe von ca. 91080 Bytes

Code: (dl )
1
2
3
4
5
6
7
8
9
sub sys_seek {
  sysopen my $fh, "file.txt", O_RDONLY or die $!;
  flock $fh, LOCK_EX or die $!;
  print "Position: ", sysseek($fh, 0, SEEK_CUR), "\n";
  <$fh>;
  print "Position: ", sysseek($fh, 0, SEEK_CUR), "\n";
}

foo();


Position: 0 but true
Position: 4096


Jetzt ist auch klar, warum sysseek() etwas anderes zurückgibt! readline()
scheint immer 4096 Bytes zu buffern. sysseek() gibt also die Position
zurück, bis zu der gebuffert wurde, also bis wohin genau die Datei schon
eingelesen wurde. tell() gibt die aktuelle Position von readline() zurück,
was für gewöhlich das aktuelle Zeilenende ist. Davon weiß allerdings
sysseek() wenig. Deshalb ist die Vermischung von Beidem nicht so
prickelnd.

viele edits... sorry\n\n

<!--EDIT|opi|1182857837-->
What is a good module? That's hard to say.
What is good code? That's also hard to say.
One man's Thing of Beauty is another's man's Evil Hack.

View full thread Sysopen in Kombination mit seek/sysseek und print