Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

djberg96 (2603)

djberg96
  (email not shown publicly)

Journal of djberg96 (2603)

Friday January 25, 2002
02:16 PM

Interesting discoveries

[ #2418 ]

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);

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.