Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] matching an array

Expand Messages
  • Nick Keeling
    You could use foreach (@category) { $uniqueCategories{$_}+=1; } This will place them in a hash and count how many occurrences of each item in the @category
    Message 1 of 3 , Jan 3, 2004
    • 0 Attachment
      You could use

      foreach (@category)
      {
      $uniqueCategories{$_}+=1;
      }

      This will place them in a hash and count how many occurrences of each
      item in the @category array.

      >>> toro_mfg@... 12/31/03 12:06PM >>>
      I have a list say, @category = (dog, dog, cat, mouse, cat, dog);

      and I want to parse through it and return a list with just unique
      names.

      @uniqueCategories = (dog, cat, mouse);

      I tried

      @uniqueCategories = ();
      foreach (@category) {
      if(!/$_/, @uniqueCategories){
      push @uniqueCategories, $_;
      }
      }

      but this doesn't seem to work. Help anyone?


      Unsubscribing info is here:
      http://help.yahoo.com/help/us/groups/groups-32.html

      Yahoo! Groups Links

      To visit your group on the web, go to:
      http://groups.yahoo.com/group/perl-beginner/

      To unsubscribe from this group, send an email to:
      perl-beginner-unsubscribe@yahoogroups.com

      Your use of Yahoo! Groups is subject to:
      http://docs.yahoo.com/info/terms/
    Your message has been successfully submitted and would be delivered to recipients shortly.