in reply to Re: help with search and match (Homework?)
in thread help with search and match

this is actually not school related....anyways, i tried this:
open(FILE1, "$file1") || die "can't open file"; open(FILE2, "$file2") || die "can't open file"; while (<FILE2>) { chomp; @array2= split; while(<FILE1>) { chomp; @array1 = split; } if ($array1[0] eq $array2[0]) print "match\n"; if ($array1[1] == $array[2]) { print $array[1]; } else { print " no match"; } }

Replies are listed 'Best First'.
Re (3): help with search and match (Homework?)
by talexb (Chancellor) on Aug 26, 2002 at 17:20 UTC
    I can see a number of problems with your code ..
    • The first time through the FILE2 loop, you'll read all of FILE1 and it will come up empty after that.
    • You are reading all of FILE1 for each line of FILE2 -- that's not efficient.
    • I would rename your array variables as array1 and array2 (corresponding, of course, to FILE1 and FILE2)
    Second to last, I would reformat the code as:
    open(FILE1, "$file1") || die "can't open file"; open(FILE2, "$file2") || die "can't open file"; while (<FILE2>) { chomp; @array2= split; while(<FILE1>) { chomp; @array1 = split; } if ($array1[0] eq $array2[0]) { print "match\n"; if ($array1[1] == $array[2]) { print $array[1]; } else { print " no match"; } } }
    Finally, check out the other good responses to the original question .. your approach should be abandoned.

    --t. alex
    but my friends call me T.

Re: Re: Re: help with search and match (Homework?)
by John M. Dlugosz (Monsignor) on Aug 26, 2002 at 18:53 UTC
    Also, use strict; use warnings; to catch some of your typos (and declare your variables).
Re: Re: Re: help with search and match (Homework?)
by mephit (Scribe) on Aug 26, 2002 at 19:11 UTC
    This looks alot like a question from a few days ago. See my response in that thread.

    --

    There are 10 kinds of people -- those that understand binary, and those that don't.