in reply to Opening Unknown Filenames
Your algorithm (as written, it doesnt correspond to your code in my mind) is an accident waiting to happen. Luckily your implementation while having issues already covered doesnt have the problem. It should IMO look like this:
1. Get list of all files in '/var/log/cr_user' 2. Foreach file in list 3. read file contents and process each line of CSV text 4. close and then delete the file 5. Exit
something like this maybe?
use strict; use warnings; my $path='/var/log/cr_user'; # =shift @ARGV; # is better IMO # clear @ARGV of junk so we can use <> for file IO @ARGV=(); #get the files my @files=glob "$path/*"; # as long as there are still files while (@files) { #remove the first file from list and store it my $to_delete=shift @files; # stick the file in @ARGV so <> can do its ting. push @ARGV,$to_delete; # iterate over the lines in the file while (<>) { # lose newline chomp; # split the line by ',' my @vars=split/,/; # print the results print join(" ",@vars),"\n"; } # delete the file unlink $delete; } #and fall of the end of the script "gracefully exit :-)"
This is untested, but potential typos aside it should do the trick.
HTH
|
|---|