in reply to calculating the mode

Hi !

In your code, you read from FILE :

while (<FILE>) { ... }

but FILE is never opened... I think you should check that before anything else...

Moreover, you never use any of the file descriptors you opened. I am doubtful ...

HTH

zejames