agreed, although I was neither critiquing his perl (or bashing him on the
head for that matter), but simply answering his question why his
comparison was failing. I love your comment regarding the need for chomp
btw:)
On Sun, 11 Feb 2001, Cameron Simpson wrote:
> 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";
> }
> }
_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list