www.webdeveloper.com
Results 1 to 4 of 4

Thread: Looping through an array

  1. #1
    Join Date
    Mar 2003
    Posts
    8

    Question Looping through an array

    I need to write a loop that parses form data against an array. The form data is in the scalar, $search. The array contains keywords that should be matched, and is called @Keywords. What type of loop should I do? I'm thinking a foreach because I need all values of the array checked. But I'm not sure how to get the program to search for each variable. Any thoughts? Thanks.


    Scott

  2. #2
    Join Date
    Nov 2002
    Location
    NY, USA
    Posts
    731
    You could use a for loop, but this is more of a situation for grep.
    Code:
    my @matches = grep { /$search/ } @Keywords;
    for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
    {for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";

  3. #3
    Join Date
    Mar 2003
    Posts
    8

    next question

    the new array, @matches will then take all of the keywords that match and store them. Now, I need to say something like this:

    if (@matches "equals one or more words" in @Keywords)
    {
    Save to external file A; #I have this
    }
    else
    {
    Save to external file B;
    }

    What can I use for "equals one or more words"?

    Thank you.


    Scott

  4. #4
    Join Date
    Nov 2002
    Location
    NY, USA
    Posts
    731
    If you mean by words that it matches one of more elements in @Keywords then it is as simple as:
    Code:
    if (@matches > 1) {}
    for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
    {for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles