
pratul
New User
Jul 25, 2011, 7:29 AM
Post #1 of 2
(6921 views)
|
|
I need a code for duplicate checker in perl
|
Can't Post
|
|
Hi everyone..I am a perl newbie..I have a tab delimited text file with two columns. Now I am trying to make a code that will append the text file after taking user input. But it should check the whole for duplicates. If duplicates found, it doesn't append. if there's no duplicate, then it appends. Please note that it only check the first column for duplicate. Here's the code I have written. Currently, it only checks the first row. And if duplicate is found, it shows a message like "Found match" and also appends the duplicates. I have attached my text file also. The code is:
print "Please write your name and address below\n"; $input=<STDIN>; $input1=<STDIN>; chomp $input; chomp $input1; open FILE, "C:/Software/new1.txt" or die $!; while ($line=<FILE>) { @line=split("\t", $line); ($name)=@line; chomp($name); if ($input=~ m/$name/) { print "Name matching\n"; } open FILE, ">>C:/Software/new1.txt" or die $!; print FILE "$input\t$input1"; } close (FILE); exit; Please note that, it also doesn't match the user input strictly. Like if the first column of first row is abc and the user input was abcd..still it takes the value.. Please help
|