package sizes; require 5.001; use strict; use vars qw(@ISA $VERSION); $VERSION = "1.0"; @ISA = qw(Exporter); sub new { my $self = {}; my $pkg = shift; $self->{dir} = shift; $self->{pat} = shift; $self->{dh} = undef; bless $self; opendir $self->{dh}, $self->{dir} || warn "cannot open dir: [".$self->{dir}."] $!\n"; return $self; } sub check { my $self = shift; $self->{size} = 0; while (my $file = readdir($self->{dh})) { next unless $file =~ /$self->{pat}/; my $fqpn = $self->{dir}.'/'.$file; print STDERR "size $fqpn: ".$self->{size}."\n"; $self->{size} += -s $fqpn; print STDERR "size $fqpn: ".$self->{size}."\n"; } print STDERR "rewinding\n"; rewinddir($self->{dh}); return $self->{size}; } sub DESTROY { my $self = shift; closedir $self->{dh}; } 1; use sizes; $checker = sizes->new($dir,$pat); $size=$checker->check();