use Croak qw/croak/; # (update; don't forget this line, if making a module) sub check_new_paths { my ( $chkpath, $reflist ) = @_; # path to monitor, list of prev. contents my %old_list; if ( -f $reflist ) { open( LST, "<", $reflist ) or croak( "Can't read $reflist: $!" ); %old_list = map { chomp; $_ => undef } ; close LST; } if ( ! -d $chkpath ) { croak( "$chkpath is not a directory" ); } my @new_list = grep { -d } <$chkpath/*>; # NB: file glob does not catch "$chkpath/.any-dot-initial-dirname" my @added_list; if ( keys %old_list ) { for my $p ( sort @new_list ) { push @added_list, $p unless exists( $old_list{$p} ); } } else { warn sprintf( "Creating new list %s with %d items\n", $reflist, scalar @new_list ); } open( LST, ">", $reflist ) or croak( "Can't write $reflist: $!" ); print LST "$_\n" for ( @new_list ); close LST; return @added_list; } #### my @new_list = split /\x0/, `find $chkpath -type d -print0`;