in reply to parsing a directory of log files.
You truncate/open a file for output and then try to read from it? I hope you made a backup of the directory before you ran that script with $dir set to "." because the script would have obliterated all the data files. (Running it with some directory name in @ARGV would have saved your input data from oblivion, but wouldn't have gotten anything done.)$dir= shift || '.'; opendir DIR, $dir or die "Can't open directory $dir: $!\n"; while ($file= readdir DIR) { next if $file=~/^\./; open (FH, ">", "$file") or die "Can't open file $file: $!\n"; my @file_lines=<FH>;
The second snippet avoids that problem, but still shares another problem with the first version: if $dir is set to something other than "." (i.e. via @ARGV), the open statement would need to be like this in order to do what you want:
Luckily, when you do it that way, it still works when $dir is set to "."open (FH, "$dir/$file") ...
Put all that together with the other replies, and you should get pretty close to a working script.
|
|---|