in reply to Re: @array1 vs @array2
in thread @array1 vs @array2

I tried the first example and it only printed the customer name with a count of 0.
open(FILE, "data.txt"); open(FILE2, "info.csv"); @data = <FILE>; @data2 = <FILE2>; ## TEST CODE foreach (@data) { ($id,$name,$ref) = split( /,/, $_); print "The customer is $name"; $no = grep { m/,$id$/ } @data2; print "We have $no docs by this $id\n"; } close(FILE); close(FILE2); exit; ## END TEST CODE

Am I not thinking clearly(as I usually don't) on this or what?
Here's the output:
he customer is Customer1 coWe have 0 docs by this 1
The customer is Customer2 coWe have 0 docs by this 2
The customer is Customer3 coWe have 0 docs by this 3

Replies are listed 'Best First'.
Re: Re: Re: @array1 vs @array2
by mikfire (Deacon) on Mar 19, 2001 at 22:47 UTC
    Remove the comma from the regex.

    But really, do not do it this way. Given that you are processing the entire contents of @array2 for each element in @array1, you have suddenly created an O(n^2) algorithm. This will hurt very quickly if either @array1 or @array2 gets very large. Especially since I would expect @array2 >> @array1.

    Try the one of the two hash solutions presented ( either one does basically the same thing ).

    mikfire