1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
my %files; read_files(\%files,'dir1'); read_files(\%files,'dir2'); my @sorted=map{$_->[0]}sort{$a->[1] <=> $b->[1]}map{[$_,(/(\d+)/)]}keys(%files); for my $file (@sorted) { my @paths=map{$_.'/'.$file}@{$files{$file}}; # mach was mit den Pfaden print "FILES: ".join(' , ',@paths); } sub read_files { my $files=shift; my $dir=shift; opendir(my $dh, $dir) or die("error opedir $dir ($!)\n"); while(my $file=readdir($dh)) { next unless($file=~/\d+\.txt/); push(@{$files->{$file}},$dir1); } closedir($dh); }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#! /usr/bin/perl use strict; use warnings; my %files; my $dir_alt = 'C:\Users\alt'; my $dir_neu = 'C:\Users\neu'; read_files(\%files,'$dir_alt'); read_files(\%files,'$dir_neu'); my @sorted=map{$_->[0]}sort{$a->[1] <=> $b->[1]}map{[$_,(/(\d+)/)]}keys(%files); sub read_files { my $files=shift; my $dir=shift; opendir(my $dh, $dir) or die("error opedir $dir ($!)\n"); while(my $file=readdir($dh)) { next unless($file=~/\d+\.txt/); push(@{$files->{$file}},$dir); } closedir($dh); }
2012-04-03T09:37:14 Trommelwirbel
Quoteer kickt mich bei öffnen raus "No such file or dictionary" zeile 29.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
#! /usr/bin/perl use strict; use warnings; my $dir_alt = 'C:\Users\alt'; my $dir_neu = 'C:\Users\neu'; opendir my $dh_alt, $dir_alt or die $!; opendir my $dh_neu, $dir_neu or die $!; my @files_alt = grep { -f "$dir_alt/$_" } readdir $dh_alt; closedir $dh_alt; my @files_neu = grep { -f "$dir_neu/$_" } readdir $dh_neu; closedir $dh_neu; my @alle=( @files_alt,@files_neu); @alle = sort(@alle); my $laenge = @alle; my $n = 0; my @new = (); while($n <$laenge) { print "bin bei ",$alle[$n]," ","\n"; push @new,$alle[$n]; if (not exists $alle[$n+1]){ last; } if( $alle[$n] eq $alle[$n+1]){ pop @new; } $n+=1; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#!/usr/bin/perl use strict; use warnings; my $dir_alt = 'C:\Users\alt'; my $dir_neu = 'C:\Users\neu'; my %files_alt = read_dir_files($dir_alt); my %files_neu = read_dir_files($dir_neu); my %files_all=(%files_alt,%files_neu); my @new; for my $file (keys(%files_all)) { next if($files_alt{$file} && $files_neu{$file}); push(@new,$file); } print join("\n",@new)."\n"; ############################################################ sub read_dir_files { my $dir=shift; opendir(my $dh, $dir) or die("Error opendir $dir ($!)\n"); my @files=grep { -f "$dir/$_" } readdir($dh); closedir($dh); return map {$_ => 1} @files; }