[Cascavel-pm] Re: Comparacao de diretorios e manipulacao de

Graciliano M. P. gmpowers em terra.com.br
Sexta Fevereiro 27 17:35:08 CST 2004


Bom, cá está uma solução pure Perl.

GMP

#!/usr/bin/perl

  my @files = catdir('/foo/somedir' , 0 , 1 , 1) ;

  foreach my $files_i ( @files ) {
    if ( $files_i =~ /(.*?)\.t2t$/) {
      my $file_html = "$1.html" ;

      my $t2t_time = (stats($files_i))[9] ;
      my $html_time = (stats($file_html))[9] ;

      if (!-e $file_html || $t2t_time > $html_time) {
        print "$files_i\n" ;
        call("txt2tags -t html $files_i") ;
      }
    }
  }

########
# CALL #
########

sub call {
  my ( $cmd ) = @_ ;

  open (my $ipc,"| $cmd") ;
  my $log_read = join("", <$ipc>) ;
  close ($ipc) ;

  $log_read =~ s/\r\n?/\n/gs ;

  return($log_read) ;
}

##########
# CATDIR # (DIR , CUT_BASE , RECURSIVE , ONLY_FILES)
##########

sub catdir {
  my ( $dir , $cut , $r , $f ) = @_ ;

  my @files ;

  my @DIR = $dir ;
  foreach my $DIR ( @DIR ) {
    my $DH ;
    opendir ($DH, $DIR);

    while (my $filename = readdir $DH) {
      if ($filename ne "\." && $filename ne "\.\.") {
        my $file = "$DIR/$filename" ;
        if ($r && -d $file) { push(@DIR , $file) ;}
        else {
          if (!$f || !-d $file) {
            $file =~ s/^\Q$dir\E\/?//s if $cut ;
            push(@files , $file) ;
          }
        }
      }
    }

    closedir ($DH) ;
  }

  return( @files ) ;
}






Mais detalhes sobre a lista de discussão Cascavel-pm