Hi, On 07/02/2014 08:04 PM, Andreas Krieger wrote: > We had the same problem viewing the CA certificate stored within our > PostgreSQL DB. We are using mysql - so perhaps this is the difference and the $db class returns something different here.
> We could fix this by editing the file > /opt/openca/ca/modules/perl5/OpenCA/AC.pm thanks for sharing this solution > The problem was the line: if( not (@certs = $self->{db}->searchItems ( > > I think assigning something to a variable is always true. not necessarily. Look at the following example: #!/usr/bin/perl -w use strict; my @A; sub foo(){ my $B = <STDIN>; if ($B =~ /N/){ return; } return $B; } if (not (@A = foo())){ print STDOUT "works! \n"; } else { print STDOUT "@A\n"; } If you type "N" it prints out "works!" which is the case we have in AC.pm, if you type anything else, this input is repeated. This is really higher level Perl magic - or some may also call it "bad programming style". What happens is: The function foo() returns something (the value of $B) or nothing. If it returns nothing, this is assigned to the array @A. It is important to actually return nothing, because if you ommit the return command the result of the last statement is returned, and if you return something like undef or an empty array or so, that's at least something which can be assigned - even if it isn't an array. Perl tries to convert and if it is not an array, it assigns the scalar value to the first entry of the new array. Finally, the not-(...)-operation around the assignment takes the value assigned and tries to negate it, which normally won't work if it is an array. So almost always it goes into the else-branch, even when the array is empty (0 elements) or if the first element is an "undef" value. In the above example, when foo() has returned "nothing" the array itself is undefined and then negating it evaluates as "true" and the if-branch is executed. However, it took me quite a while to find out what happens here ;-) Coming back to AC.pm: here $self->{db}->searchItems() depends on which type of $db instance we have. If searchItems returns nothing for a mysql database and returns an empty array or "undef" for postgresql we already have a different behavior. Cheers, Martin ------------------------------------------------------------------------------ Open source business process management suite built on Java and Eclipse Turn processes into business applications with Bonita BPM Community Edition Quickly connect people, data, and systems into organized workflows Winner of BOSSIE, CODIE, OW2 and Gartner awards http://p.sf.net/sfu/Bonitasoft _______________________________________________ Openca-Users mailing list Openca-Users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openca-users