in reply to Re^2: log file in perl.
in thread log file in perl.

What's stopping you? The answer to your question lies in you trying to understand the code you have. You already have the file name in your $file variable. You can get information on files using the -X family of operators, but you should know that already since your code contains -f. stat might also be helpful.

I find it odd that you say it's working now, as I took your posted code, attempted to run it, and obtained the errors:

String found where operator expected at fluff.pl line 35, near ") "Dir +ectories: $directory_count |"" (Missing operator before "Directories: $directory_count |"?) print (...) interpreted as function at fluff.pl line 36. String found where operator expected at fluff.pl line 36, near ") "Fil +es: $file_count\n"" (Missing operator before "Files: $file_count\n"?) syntax error at fluff.pl line 35, near "$OUTF) " syntax error at fluff.pl line 36, near ") "Files: $file_count\n"" Execution of fluff.pl aborted due to compilation errors.

I can also spot a number of other issues that would be caught by strict and warnings, as you claim to have implemented Re^2: Perl Script to count files and directories is not working.. As an internet programming forum, PerlMonks is ridiculously respectful and helpful to the neophyte. We do not have patience for people who show no effort. I highly recommend you read How To Ask Questions The Smart Way and meditate on it before posting again.

Replies are listed 'Best First'.
Re^4: log file in perl.
by Anonymous Monk on Aug 28, 2010 at 00:38 UTC
    Hi,

    I am sorry I did not mean to say its working for a wrong code. It was pasted from a wrong file which was not working earlier.This happened in a rush. I am pasting the code which is working fine now for me and I am also tweaking it as per the suggestions given stat and -x.

    #!/usr/local/bin/perl use warnings; use strict; my $dir= 'c:\My documents\perl scripts\new folder'; my $directory_count=0; my $file_count=0; my $outfile = 'log.txt'; open my $OUTF, '>', $outfile or die "can't create logfile;$!"; opendir (DIR, $dir); my @files = readdir(DIR); foreach my $files(@files) { print {$OUTF}"$files |";} foreach my $file(@files) { if (-d "$dir/$file") { $directory_count++; } else { $file_count++; } } print { $OUTF} "$directory_count |"; #print { $OUTF} "$file_count \n";