On Fri, Feb 09, 2001 at 09:40:14PM -0500, Charles Galpin 
<[EMAIL PROTECTED]> wrote:
| Cameron's solution is far simpler, but since you are attempting to do this
| in perl, I'll tell you why your comparison is failing
[...]
| > foreach $item (@control_list) {
| >     chop($item);
| >     foreach $file (@files) {
| >             chop($file);
| >             if($file == $item) {
| >                     print "$item";
| 
| You are using the '==' which is used to compare two numbers. Try using
| 'eq' instead, which will treat it's arguments as strings.

While we're critiquing his perl, let's beat him about the head for using
an O(n^m) algorithm, which scales by the product of the file list and
the search tree. He would be wise to stuff the files to notice into a
hash as the keys. Then the check is pretty much O(1) and the the loop
as a whole O(n). Eg:

    for my $item (@control_list)
    { $hash{$item}=1;
    }

    for my $file (@files)
    { chomp($file);             # this should have happened when they were
                                # read in but there you go ...
      if (exists $hash{$file})
      { print "$file\n";
      }
    }

Gads! Do they teach programmers nothing these days?
-- 
Cameron Simpson, DoD#743        [EMAIL PROTECTED]    http://www.zip.com.au/~cs/

Saw, n: A trite popular saying, or proverb. So called because it makes its
way into a wooden head.
Ambrose Bierce (1842-1914), U.S. author. The Devil's Dictionary (1881-1906).



_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to