in reply to Re^2: selcting a specific file
in thread selcting a specific file

Your code won't compile. That's not very dire. Just stay comitted to it ;-)

use strict; use warnings; my $path = '/tmp/allfiles'; my $outpath = '/tmp/nonemptyfiles'; opendir my $dh, $path or die $!; my @files = grep /\.log$/ && -f "$path/$_" && !-z "$path/$_", readdir +$dh; closedir $dh; for my $fn (@files){ open my $fr, '<', "$path/$fn" or die "IN: $fn $!"; open my $fw, '>', "$outpath/$fn" or die "OUT: $fn $!";; while( <$fr> ) { printf $fw "$1 $2\n" if /(\S+)\s+(\S+)/ } }

Try to study the example and bear some idomatic expressions in mind like indirect file handles and checks for success ...

Regards

mwa

Replies are listed 'Best First'.
Re^4: selcting a specific file
by Anonymous Monk on Oct 23, 2007 at 00:18 UTC
    #!/usr/bin/perl $dest="/home/perl/sra/"; print "the source direcotry name:\n"; chomp(my $source=<STDIN>); opendir($DIR, $source) or die "cannot open the directory '$source': $!"; @files =@files = grep { /\.log$/ } readdir ($DIR); foreach my $x (my @files){ open READFILE, "$source/$x"; open WRITEFILE, ">$dest$x"; while(<READFILE>){ chomp; my @parts = split(/\s/, $_); print WRITEFILE $parts[1], " ", $parts[0], "\n"; } close WRITEFILE; close READFILE; } closedir($DIR)
    this code works out but the options given by you for selecting and copying only non empty files doesnt work out!! please help me out!!
A reply falls below the community's threshold of quality. You may see it by logging in.