Interesting discoveries

djberg96 on 2002-01-25T19:16:14

Today I learned how to pass a data structure through a socket using the 'nstore_fd' function from the Storable.pm module. Sweet.

I also discovered one source of "Illegal Seek" errors today. Turns out that if you call 'stat' on a 0 byte file, $! will be set to "Illegal Seek". This was hosing up one of my client-server plugin modules that I'm working on. How effing lame. The solution was a simple "defined" call, I realize, but it's still dumb.

I also discovered, while previewing this post, that the PRE tag doesn't seem to work the way it should.

Anyway, here's some test code. Just make sure you've got at least one 0-byte file in the current directory.

#!/usr/bin/perl -w use strict; use Cwd;

my $cwd = cwd();

opendir(DIR,$cwd) or die "Could open $cwd: $!\n"; while(my $file = readdir(DIR)){ next if $file =~ /^\.$|^\.\.$/; my $size = (stat($file))[7] or print "Warning: $file=>$!\n"; print "File: $file, "; print "Size: $size\n"; } closedir(DIR);