![]() |
Little perl problem, help needed
im just trying to erase duplicates entries .. here's what i got:
basically, i search my database for my own stuff first and its put in @gals2. Now im searching @gals2 for the current result ($_) and if its a match, then current result is replaced by $nothing which is $nothing = ""; while(my @gals = $sth->fetchrow) { if (@gals2 =~ /$_/){ $_ = $nothing; } its not displaying any change at all in my results.. it's as if that whole code didn't exist. Any input will be appreciated, Jon |
trying to remove it from the array?
|
yeah if the current result matches anything in the first array, i want it to be remove from the current one
|
|
a) If @in is sorted, and you want @out to be sorted: (this assumes all true values in the array)
$prev = 'nonesuch'; @out = grep($_ ne $prev && ($prev = $_), @in); This is nice in that it doesn't use much extra memory, simulating uniq(1)'s behavior of removing only adjacent duplicates. It's less nice in that it won't work with false values like undef, 0, or ``''; ``0 but true'' is ok, though. b) If you don't know whether @in is sorted: undef %saw; @out = grep(!$saw{$_}++, @in); c) Like (b), but @in contains only small integers: @out = grep(!$saw[$_]++, @in); d) A way to do (b) without any loops or greps: undef %saw; @saw{@in} = (); @out = sort keys %saw; # remove sort if undesired e) Like (d), but @in contains only small positive integers: undef @ary; @ary[@in] = @in; @out = @ary; |
i had come across that one but it wont work with my method of displaying results.
First, i display my own results first, then all the rest. My own results are in an array and the second one, in another array. I need to do it exactly as it happens. In the while loop, i need every $_ to check if its present in the first array. If its present, i need $_ to skip to the next result |
@gals = sort @gals;
$c=0; foreach(@gals) { if ($gals[$c] eq $gals[$c+1]) { $nothing=$youstupid; } else { push(@mygal, $gals); } $c++; } Try that you dumbasses!! |
Quote:
|
Quote:
|
Edit above to this :
push(@mygal, $gals[$c]); |
Hmmm is there any faster way of doing it?
i think there's something wrong with if(@gals =~ /$_/) am i using the right method to search an array or is that method only used to search strings? |
You really should get the results in one query if at all possible. I tried to help you in the other thread but without seeing the structure of the DB I really can't even begin to guess how your system is laid out. If you'd post your db structure and some sample data we can figure something out.
|
im not that good in perl, im still learning, but i think the code above will remove duplicate entries next to each other in the results list. That is barely ever the case. Which is why i need it to check everytime its a new $_ if its in the first array. If it is, it needs to be skipped
|
Quote:
Duh, why don't you put all the shit in an array and sort it; which makes the duplicates next to each other!!! Damn; I didn't think I needed to explain that. |
Quote:
|
Quote:
|
Quote:
|
i cant sort it because it has to be done on-the-fly.
i tried doing that before but there was a huge problem with foreach which was displaying everything wrong. Even a guru coder had trouble finding the problem there. It just didn't work. |
Quote:
|
Quote:
Now you say the "Foreach" verb is broken! More like your guru didn't add the "$c++;" to the loop and guess what happens...it dislplays eveything wrong. |
sorry bro didn't see ya icq I'm passing out if ya still need help hit me tommorrow
|
All times are GMT -7. The time now is 03:07 AM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123