7 my $dir = '/usr/local/etc/freeside/export/cdr';
10 #XXX glob might not handle lots of args at some point...
11 foreach my $file ( glob("$dir/*/CDR*-spool.CSV") ) {
13 $file =~ m{(\d+)/CDR(\d+)-spool.CSV$}
14 or die "guru meditation #54: can't parse filename: $file\n";
15 my($custnum, $date) = ($1, $2);
19 while ( -e "$dir/$custnum/CDR$date$alpha.CSV" ) {
20 $alpha++; # A -> Z -> AA etc.
22 my $newfile = "$dir/$custnum/CDR$date$alpha.CSV";
24 rename $file, $newfile
25 or die "$! moving $file to $newfile\n";
28 my $lock = new IO::File ">>$newfile"
29 or die "can't open $newfile: $!\n";
30 sleep 1; #just in case. i guess there's still a *remotely* possible
31 #race condition, but i'm not losing any sleep over it... (rimshot)
33 or die "can't lock $newfile: $!\n";
34 #okay we've got the lock, any pending write should be done...
36 print "$custnum: $newfile\n";