Similar but a little more compact
#!/usr/bin/perl -w use strict; use autodie; print "Enter the path where the log file is placed: "; chomp(my $dir = <STDIN>); opendir DIR, $dir; my @text = grep (/\.txt$/, readdir DIR); # <--- note the '$' here closedir DIR; print "Enter the path where to save the report: "; chomp(my $dest_dir = <STDIN>); open (my $FH1, '>', "$dest_dir/result.txt") if( scalar(@text) > 0); foreach my $textfile (@text){ print $FH1 $textfile,"\n"; } close $FH1;
In reply to Re: Unable to read a file
by pvaldes
in thread Unable to read a file
by ckj
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |