GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Little perl problem, help needed (https://gfy.com/showthread.php?t=360620)

archael 09-22-2004 09:58 PM

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

irishfury 09-22-2004 10:17 PM

trying to remove it from the array?

archael 09-22-2004 10:21 PM

yeah if the current result matches anything in the first array, i want it to be remove from the current one

Babaganoosh 09-22-2004 10:25 PM

http://www.perldoc.com/perl5.6.1/pod...list-or-array-

irishfury 09-22-2004 10:26 PM

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;

archael 09-22-2004 10:35 PM

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

blackmonsters 09-22-2004 10:35 PM

@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!!

Babaganoosh 09-22-2004 10:38 PM

Quote:

Originally posted by archael
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

That's going to be pretty slow...especially if that array gets big. I'd suggest finding another way to do it.

irishfury 09-22-2004 10:39 PM

Quote:

Originally posted by Armed & Hammered
That's going to be pretty slow...especially if that array gets big. I'd suggest finding another way to do it.
yup that will be slow...

blackmonsters 09-22-2004 10:44 PM

Edit above to this :

push(@mygal, $gals[$c]);

archael 09-22-2004 10:46 PM

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?

Babaganoosh 09-22-2004 10:46 PM

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.

archael 09-22-2004 10:48 PM

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

blackmonsters 09-22-2004 10:55 PM

Quote:

Originally posted by archael
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

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.

irishfury 09-22-2004 10:58 PM

Quote:

Originally posted by blackmonsters
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.

he did say he was just learning :winkwink:

blackmonsters 09-22-2004 11:03 PM

Quote:

Originally posted by irishfury
he did say he was just learning :winkwink:
I know. I'm just being a dick because there's no flames on the board right now.:1orglaugh

irishfury 09-22-2004 11:06 PM

Quote:

Originally posted by blackmonsters
I know. I'm just being a dick because there's no flames on the board right now.:1orglaugh
lol continue on :thumbsup

archael 09-22-2004 11:08 PM

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.

SpikeHeel 09-22-2004 11:10 PM

Quote:

Originally posted by blackmonsters
I know. I'm just being a dick because there's no flames on the board right now.:1orglaugh
hahaha...i commend you for your initiative to be the flame starter, blackmonsters! way to go! :1orglaugh

blackmonsters 09-22-2004 11:21 PM

Quote:

Originally posted by archael
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.

Your guru is probably a moron who couldn't pogram a re-dial button on a cellphone.

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.

irishfury 09-23-2004 01:41 AM

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