Current location: Hot Scripts Forums » Programming Languages » Perl » file into an array, then appending array only if no duplicates


file into an array, then appending array only if no duplicates

Reply
  #1 (permalink)  
Old 05-15-04, 04:21 PM
djpennin djpennin is offline
New Member
 
Join Date: May 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy file into an array, then appending array only if no duplicates

i have a file that i read into an array.
then i used that array and step through it one by one.
while stepping through it i run some processes that write back to the array, but the problem i am having is that i'm gettind duplicates in the array. what i'd like to do is before writing back to the array, is to check to see if that value exists, and if it does not exist then write it.



for example: myfile contains A,B,C. myfile gets put into myarray. so myarray contains A,B,C. I read myarray[0] and run some processes. the processes return C,D,E. I write that back to the array, and myarray looks like A,B,C,C,D,E. I have 2 C's. How would i make it so that i check for duplicates first and then write to the array so my final result would be A,B,C,D,E.

the one problem is, that this is a real time process, so i keep reading the array as values are added to it.

plz help!
djpennin@yahoo.com
Reply With Quote
  #2 (permalink)  
Old 05-15-04, 10:52 PM
Chas Chas is offline
Coding Addict
 
Join Date: Oct 2003
Location: California
Posts: 359
Thanks: 0
Thanked 0 Times in 0 Posts
Can you post what code you have now so we can see what's going on.

~Charlie
Reply With Quote
  #3 (permalink)  
Old 05-17-04, 01:04 PM
yzxix's Avatar
yzxix yzxix is offline
New Member
 
Join Date: Mar 2004
Location: East Coast
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Here's a rather long-winded approach, but it's easy to read:

Code:
foreach $first (@secondarray) {
	$elcount=0;
	foreach $second (@myarray) {
		if ($first eq $second) {
			delete $myarray[$elcount];
		}
		$elcount++;
	}
}
push @myarray, @secondarray;
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I write an array to a file? bark PHP 2 03-30-04 12:28 PM
Upload Script Problem!!! seanknighton Perl 0 03-21-04 09:54 PM
write to beginning of file or reverse an array of binary data abtimoteo Perl 1 01-20-04 10:09 AM
linking to iframe not working :( j0d JavaScript 5 01-19-04 08:14 PM
Upload file to table so ONLY files tied to primary key are displayed in record? grafixDummy PHP 4 12-20-03 04:28 PM


All times are GMT -5. The time now is 04:58 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.