in reply to comparing elements of two arrays

Your code works for me:
@array1[2] = @array2[2] = 'hi'; if ($array2[2] eq $array1[2] ) { print $array2[2]; print "\n"; } # prints this: hi
I suspect I'm missing something, though.

Could you post your arrays, too? I think a little more detail is needed.

Remember that 'eq' is for strings, and '==' is for numbers.

Replies are listed 'Best First'.
(jeffa) 2Re: comparing elements of two arrays
by jeffa (Bishop) on Dec 24, 2001 at 00:58 UTC
    mrbbking is right, we need more info from you. After seeing the solution for array from file and compare, i wonder if you need to chomp at least one of your arrays first.

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    F--F--F--F--F--F--F--F--
    (the triplet paradiddle)
    
Re: Re: comparing elements of two arrays
by luke123 (Initiate) on Dec 25, 2001 at 00:51 UTC
    My arrays are strings. Each elements is one line from a file. This is how I read the data and insert it into 2 arrays:
    $infile1 = "sept13.csv"; $infile2 = "sept14.csv"; open (infile1); @array1=<infile1>; close(infile1); open (infile2); @array2=<infile2>; close(infile2);
    The format of file(.csv) is as follows. Last Name, First Name, WebCT ID, Password, Courses Calvert,Aaron,aacalvert,0120015,lib101 Accardo,Andrea,aaccardo,0110659,biol361h:cost280h:lib100
      Slurping the whole file in like that results in a one-element array. So there is nothing at subscript 2 to compare.

      You'll need to split the lines of each file into their component parts before you can compare (what appears to be) usernames.

      ...does that make sense?