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

simple array problem

Expand Messages
  • jabir ahmed
    Hello I have a pretty simple problem ex: @a=qw( 1 2 3 4 5 6 7 ); $b=5; now i just want to check if the value of $b i.e 5 exists in the array @a or not Q 1) is
    Message 1 of 3 , Oct 7, 2005
    • 0 Attachment
      Hello
      I have a pretty simple problem

      ex:
      @a=qw( 1 2 3 4 5 6 7 );
      $b=5;

      now i just want to check if the value of $b i.e 5
      exists in the array @a or not

      Q 1) is there any way other than looping through the
      array?

      Q2 ) is there any predefined function to check the
      existance of the element in the array..

      thanks in advance

      jabir ahmed


      --
      It matters not whether you win or lose; what matters is whether I win or
      lose.
      Phone: +91 98867 01148
      email: jabirahmed@... , jabirahmed@...
      Instant Messenger:
      yahoo jabirahmed@...,msn : jabir07@...,ICQ: 56327312, Skype:
      jabirahmed


      [Non-text portions of this message have been removed]
    • Prasanna Goupal
      Hi, Q 1) is there any way other than looping through the array? No.There is no way for this. Better way you can put all element into hash and you can check
      Message 2 of 3 , Oct 8, 2005
      • 0 Attachment
        Hi,
        Q 1) is there any way other than looping through the
        array?


        No.There is no way for this. Better way you can put all element into hash and you can check existance of element using

        exists($hash{key}) function of hash.

        Keep key and value both same i.e. 5-5,6-6 etc



        Q2 ) is there any predefined function to check the
        existance of the element in the array..

        NO. There is no such function.

        Regards,
        Prasanna Goupal


        ---------------------------------
        Yahoo! Music Unlimited - Access over 1 million songs. Try it free.

        [Non-text portions of this message have been removed]
      • merlyn@stonehenge.com
        ... jabir now i just want to check if the value of $b i.e 5 jabir exists in the array @a or not This is asked frequently enough that it s (amazingly enough)
        Message 3 of 3 , Oct 8, 2005
        • 0 Attachment
          >>>>> "jabir" == jabir ahmed <jabirahmed@...> writes:

          jabir> now i just want to check if the value of $b i.e 5
          jabir> exists in the array @a or not

          This is asked frequently enough that it's (amazingly enough)
          in the "Frequently Asked Questions", included with your Perl distro.

          I recommend that you skim the "perldoc perlfaq" page at least once a
          month, perhaps starting now, until you know the questions that are
          answered there.

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