Calculating Byte Offsets with telldir : telldir « File « Perl






Calculating Byte Offsets with telldir

    

#!/usr/local/bin/perl
chdir ("c:\\temp");
use Cwd;
$dir = cwd();
opendir (DH, $dir) || warn $!;
$sByteOffset = telldir DH;
$pbo = $sByteOffset;
while ($dirName = (readdir(DH))){
   $dirNameLength = length($dirName);
   $byteOffset = telldir DH;
   $diff = $byteOffset - $pbo;
   $totalSize = $pbo - $sByteOffset;
   print "$dirName is $dirNameLength characters long at $pbo which is $diff bytes\n";
   $pbo = $byteOffset;

}

print "Total directory bytes is: $totalSize\n";

   
    
    
    
  








Related examples in the same category

1.Rewind dir
2.telldir and readdir