Hi,

Your You did not open the output file correctly. 

You try to store the File handler in a variable.
If you wish to do so open the file and store reference to the file handle.

Instead of using 
open my $f, '>', 'outputsample1' or
     die 'Failed to open outputsample1';
while (($key, $value) = each %hash)
 {

         print $f  $value."\n";

}
 close $f;


Try
open my F, '>outputsample1' or
     die 'Failed to open outputsample1';
my $f = \*F;
while (($key, $value) = each %hash)
 {

         print F  $value."\n";

}
 close $f;



Best regards,

Yaron Kahanovitch
----- Original Message -----
From: "Mihir Kamdar" <[EMAIL PROTECTED]>
To: "beginners" <beginners@perl.org>
Sent: Wednesday, August 1, 2007 1:32:54 PM (GMT+0200) Auto-Detected
Subject: Removing duplicate records

Hi,

Need your help with the following:-

I have a csv file having many records.

I want to remove duplicate records. But the record might not be entirely
duplicate. I only have to check if the 2nd, 3rd, 7th and 8th field of a
record is same as the earlier records. If it is same, then remove the
previous or the last entry. I have written something like below to achieve
this.

#!/usr/bin/perl

open(FILE,"</home/user71/RangerDatasource/Customization/TelekomMalaysia/Scripts/Tests/cprogs/files/sample1");

my $line;
my %hash;
my @file;
while ($line=readline(FILE))
{
 my @cdr=split (/,/, $line) ;
 $hash{$cdr[2],$cdr[3],$cdr[6],$cdr[7]}="@cdr";  #Add some more cdr key
fields if u want.
}
close FILE ;
open my $f, '>', 'outputsample1' or
     die 'Failed to open outputsample1';
while (($key, $value) = each %hash)
 {

         print $f  $value."\n";

}
 close $f;

But I am not getting the desired result.

Please help me out.

Thanks,
Mihir


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to