Hi Mihir
Please check line print $LOG_FILE "Count of cdrs after removing duplicates = $lines" ; And print $LOG_FILE "Count of cdrs before removing duplicates = $count" ; You are not printing new line character at the end Whenever the first line of any file is tooooooooo long unix is unable to count it And end up giving 0 count Bhargav -----Original Message----- From: Mihir Kamdar [mailto:[EMAIL PROTECTED] Sent: Tuesday, August 07, 2007 10:11 PM To: Chas Owens Cc: beginners Subject: Re: using wc -l in perl On 8/7/07, Chas Owens <[EMAIL PROTECTED]> wrote: > > On 8/7/07, Mihir Kamdar <[EMAIL PROTECTED]> wrote: > > Hi, > > > > I am trying to count the number of lines in my output file processed > > by > a > > perl code. > > > > I am not getting the syntax correct. I am doing something like > > below:- > > > > my $count1 = `wc -l < $OUT_FILE` ; > > print $LOG_FILE "Count of cdrs after removing duplicates = $count1" > > ; > > > > I am getting the following error: > > [EMAIL PROTECTED] files]$ sh: -c: line 0: syntax error near unexpected > token > > `(' > > sh: -c: line 0: `wc -l < GLOB(0x88f76d8)' > > sh: -c: line 0: syntax error near unexpected token `(' > > sh: -c: line 0: `wc -l < GLOB(0x88f76d8)' > > > > > > Plz advice, > > > > Thanks, > > Mihir > > > > That would be because $OUT_FILE is a file handle, not the file's name. > You should also not be using the qx// operator (aka backticks) to do > this, Perl can handle it just fine: > > sub count_words { > my $file = shift; > open my $fh, "<", $file > or die "could not open $file:$!"; > my $lines = 0; > $lines++ while <$fh>; > return $lines; > } > Following is my code:- #!/usr/bin/perl my $child_path = '/home/user71/RangerDatasource/Customization/TelekomMalaysia/Scripts/Tes ts/cprogs/files/child' ; my $parent_path = '/home/user71/RangerDatasource/Customization/TelekomMalaysia/Scripts/Tes ts/cprogs/files' ; my $write_path = '/home/user71/RangerDatasource/Customization/TelekomMalaysia/Scripts/Tes ts/cprogs/files/output' ; my %times ; my $continue = 1; my $count1 ; $SIG{INT} = $SIG{TERM} = sub { $continue = 0 }; while ($continue) { opendir my $dh, $child_path or die $!; while (my $file = readdir $dh) { my $fname = "$child_path/$file"; next unless -f $fname; unless (exists $times{$file}){ my $line; my %hash; opendir my $dh1,$parent_path or die $!; open (my $IN_FILE,"<","$parent_path/$file") or die $!." Parent file not found for $parent_path/$file"; my $count ; open (my $LOG_FILE,">>","$write_path/logfile2") ; for ($count=0; <$IN_FILE>; $count++) { } print $LOG_FILE "Count of cdrs before removing duplicates = $count" ; while ($line=readline($IN_FILE)) { my @cdr=split (/,/, $line) ; $hash{"@cdr[2,3,6,7]"}=$line; #Add some more cdr key fields if u want. } close $IN_FILE ; closedir $dh1 ; print $LOG_FILE "Count of cdrs before removing duplicates = $count" ; open (my $OUT_FILE,"+>","$write_path/$file.out") or die $!; while (my($key, $value) = each %hash) { print $OUT_FILE $value; } my $lines = 0 ; $lines++ while<$OUT_FILE> ; print $LOG_FILE "Count of cdrs after removing duplicates = $lines" ; close $OUT_FILE; close $LOG_FILE ; } unlink("$parent_path/$file") ; unlink("$child_path/$file") ; } closedir $dh; sleep(2) ; } At last I am trying to get the count of lines of my OUT_FILE. It is giving me the result as 0, which is not true. Where am i doing a mistake? Thanks, Mihir - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - This message is intended only for the personal and confidential use of the designated recipient(s) named above. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction, or as an official statement of Lehman Brothers. Email transmission cannot be guaranteed to be secure or error-free. Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such. All information is subject to change without notice. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/