Little perl problem, help needed

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • archael
    Registered User
    • Jun 2003
    • 51

    #1

    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
    Confirmed User
    • Aug 2003
    • 2611

    #2
    trying to remove it from the array?
    Trust no one there all snakes

    Comment

    • archael
      Registered User
      • Jun 2003
      • 51

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

      Comment

      • Babaganoosh
        ♥♥♥ Likes Hugs ♥♥♥
        • Nov 2001
        • 15841

        #4
        http://www.perldoc.com/perl5.6.1/pod...list-or-array-
        I like pie.

        Comment

        • irishfury
          Confirmed User
          • Aug 2003
          • 2611

          #5
          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;
          Trust no one there all snakes

          Comment

          • archael
            Registered User
            • Jun 2003
            • 51

            #6
            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

            Comment

            • blackmonsters
              Making PHP work
              • Nov 2002
              • 20971

              #7
              @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!!
              Free Open Source Live Aggregated Cams Script (FOSLACS)

              Comment

              • Babaganoosh
                ♥♥♥ Likes Hugs ♥♥♥
                • Nov 2001
                • 15841

                #8
                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.
                I like pie.

                Comment

                • irishfury
                  Confirmed User
                  • Aug 2003
                  • 2611

                  #9
                  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...
                  Trust no one there all snakes

                  Comment

                  • blackmonsters
                    Making PHP work
                    • Nov 2002
                    • 20971

                    #10
                    Edit above to this :

                    push(@mygal, $gals[$c]);
                    Free Open Source Live Aggregated Cams Script (FOSLACS)

                    Comment

                    • archael
                      Registered User
                      • Jun 2003
                      • 51

                      #11
                      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?

                      Comment

                      • Babaganoosh
                        ♥♥♥ Likes Hugs ♥♥♥
                        • Nov 2001
                        • 15841

                        #12
                        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.
                        I like pie.

                        Comment

                        • archael
                          Registered User
                          • Jun 2003
                          • 51

                          #13
                          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

                          Comment

                          • blackmonsters
                            Making PHP work
                            • Nov 2002
                            • 20971

                            #14
                            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.
                            Free Open Source Live Aggregated Cams Script (FOSLACS)

                            Comment

                            • irishfury
                              Confirmed User
                              • Aug 2003
                              • 2611

                              #15
                              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
                              Trust no one there all snakes

                              Comment

                              • blackmonsters
                                Making PHP work
                                • Nov 2002
                                • 20971

                                #16
                                Originally posted by irishfury
                                he did say he was just learning
                                I know. I'm just being a dick because there's no flames on the board right now.
                                Free Open Source Live Aggregated Cams Script (FOSLACS)

                                Comment

                                • irishfury
                                  Confirmed User
                                  • Aug 2003
                                  • 2611

                                  #17
                                  Originally posted by blackmonsters
                                  I know. I'm just being a dick because there's no flames on the board right now.
                                  lol continue on
                                  Trust no one there all snakes

                                  Comment

                                  • archael
                                    Registered User
                                    • Jun 2003
                                    • 51

                                    #18
                                    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.

                                    Comment

                                    • SpikeHeel
                                      Confirmed User
                                      • Oct 2003
                                      • 1531

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

                                      100% exclusive fetish content - 60% recurring CCBill program
                                      No pop-ups – No traffic leaks – No cross sells – Hosted galleries – Promo content - Free Hosting - ICQ: 228585136

                                      Comment

                                      • blackmonsters
                                        Making PHP work
                                        • Nov 2002
                                        • 20971

                                        #20
                                        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.
                                        Free Open Source Live Aggregated Cams Script (FOSLACS)

                                        Comment

                                        • irishfury
                                          Confirmed User
                                          • Aug 2003
                                          • 2611

                                          #21
                                          sorry bro didn't see ya icq I'm passing out if ya still need help hit me tommorrow
                                          Trust no one there all snakes

                                          Comment

                                          Working...