Alan writes..

>"King, Jason G" wrote:
>> 
...
>> What if FILE1 contains the number 1 and FILE2 does not contain 1 but
>> contains 11 then the regex will match against 11 and print 
>> '1' out into
>> FILE3 but the number 1 was not in FILE2 at all.
>> 
>> Additionally your syntax:
>> 
>>   print OUT grep {/$number/} @database;
>> 
>> Will mean that your output will print out multiple entries into FILE3
>> for each iteration, eg if FILE1 contained:
>> 
>>   1
>>   2
>>   3
>> 
>> And FILE2 contained:
>> 
>>   11
>>   12
>>   13
>>   14
>>   21
>>   44
>>   22
>> 
>> Then your output would be as follows (I've added the spaces in for
>> readability - in fact there would be no spaces or newlines in your
>> output):
>> 
>>   11 12 13 14 21 12 21 22 13
>>   ^^^^^^^^^^^
>>   First pass
>>               ^^^^^^^^^^^
>>               Second pass
>>                           ^^
>>                           Third pass
>> 
>> At the very least you'd have to do {/^$number$/} but that's MUCH less
>> efficient than doing { $_ == $number } - perl strips off the 
>> \n itself
>> when converting $_ to a number. But my preference is to use the hash
>> lookup detailed in my other post.
>
>well, right, but since he didn't post his data, which would have
>illuminated the situation, I assumed rather larger numbers, all 
>of the same length, which seemed to be more like what he was talking
>about. TMTOWTDI, but my suggestion was closer to his code.

Yes, probably an easy assumption to make. I still think that if you
wanted to stay closer to his code then the best option (seeing as you
are comparing numbers afterall) is to use the { $_ == $number } in the
grep.

>BTW, your solution has the two files reversed:

Really?

>> I want to check for the occurrence of each element of
>> FILE1 in FILE2. In other words, FILE2 is checked for the occurrence
>> of each of the elements in of FILE1.
>
>FILE1 == your IN and FILE2 == your DB.

That still seems to me to be exactly matching his specification, his
code and your code. Help me see what I'm missing here, I'm starting to
feel a little dopey.

You (and Kenneth) get your numbers from FILE1 and your database of
values from FILE2. In my code I renamed FILE1 to be IN and I get my
numbers from IN and I renamed FILE2 to DB and I get the database of
values from there.

-- 
  Jason King
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to