Harry Putnam wrote:
#!/usr/local/bin/perluse strict; use warnings; use File::Find; use Cwd; my %h1; my %h2; my $targ = shift; my @ckarr; my $h1ff = './h1'; my $h2ff = './h2'; my $ckff = './ckarr'; my $nf = './nf'; for($h1ff,$h2ff,$ckff,$nf){ if (-f $_){ print "deleting $_\n"; unlink $_ or die "Can't unlink $_ : $!"; } } open my $nfh,'>',$nf or die "Cannot open $nf: $!"; find({ wanted => sub { my $dir = getcwd; if(-f $dir . '/' . $_) { print $nfh "V $File::Find::name K $_\n"; $h1{$File::Find::name} = $_; $h2{$_} = $File::Find::name; push @ckarr, $File::Find::name; } },no_chdir =>0, }, $targ ); open my $h1fh,'>',$h1ff or die "Can't open $h1ff: $!";open my $h2fh,'>',$h2ff or die \"Cannot open $h2ff: $!"; open my $ckfh,'>',$ckff or die \"Cannot open $ckff: $!";foreach my $key (keys %h1){print $h1fh "V $h1{$key} K $key\n"; }foreach my $key (keys %h2){print $h2fh "V $h2{$key} K $key\n"; }for(@ckarr){ print $ckfh "$_\n"; }
close $h1fh or die "could not close $h1: $!\n"; close $h2fh or die "could not close $h2: $!\n"; close $ckfh or die "could not close $ckarr: $!\n";
print " ------- -------\n"; for($h1ff,$h2ff,$ckff,$nf){ if (-f $_){ my $file = $_; my $sz = (stat($_))[7];open my $fh,'<', $_ or die "Can't open $_: $!"; my $lines;while (<$fh>) { $lines = $.; } print " $file: lines: $lines size: $sz\n"; close $fh; } print " ------- -------\n"; }
Output is buffered. The files have to be closed for the last lines to be printed to the file.
-- Just my 0.00000002 million dollars worth, Shawn Programming is as much about organization and communication as it is about coding. I like Perl; it's the only language where you can bless your thingy. Eliminate software piracy: use only FLOSS. -- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] http://learn.perl.org/
