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

Re: [PBML] (unknown)

Expand Messages
  • merlyn@stonehenge.com
    ... M I d like to get the number of wanted items in an array. For example: M my @items = qw unwanted-1 unwanted-2 item1 item2 item3 unwanted-3 item4 M
    Message 1 of 3 , May 28, 2006
    • 0 Attachment
      >>>>> "M" == M Lewis <cajun@...> writes:

      M> I'd like to get the number of 'wanted' items in an array. For example:

      M> my @items = qw'unwanted-1 unwanted-2 item1 item2 item3 unwanted-3 item4
      M> unwanted-4';

      grep in a scalar context counts the winners:

      my $count = grep /unwanted/, @items;

      --
      Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
      <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
      Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
      See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
    Your message has been successfully submitted and would be delivered to recipients shortly.