Ola Lundqvist wrote: > > `perldoc -f do` says: > > | If "do" cannot read the file, it returns undef and sets $! to the > > | error. If "do" can read the file but cannot compile it, it returns > > | undef and sets an error message in [EMAIL PROTECTED] If the file is > > | successfully compiled, "do" returns the value of the last > > | expression evaluated. > > > > Thus relying on $! and $@ is officially sanctioned. > > I can not see that. It do not say anything about the $! or $@ when the > expression return true. It only tell that they are set when it returns > false. > > The above statements formalized: > If X return undef and set $! > if Y return undef and set $@ > if Z return $lastexpr > > I can not see anything about > if return true, set $! = 0, set $@ = 0; > > It may be so that it do that and I did some test code that verifies > that. However I do not want to rely on undocumented features too much > if there are documented features that I can rely on.
You're right, and it even actually says (in `perldoc perlvar`) that $! does NOT get set to 0 if there is no failure. Perhaps you could explicitly set $! to 0 before the do() call, though? About $@, I'm certain that it gets set to "" if the file could be read and compiled successfully. > > I think the "check whether do() returns true" idiom is a remnant from > > old times when Perl didn't know exceptions ($@). > > This is the result of the test code: > > Condition return $! $@ > -------------------------------------- > Read error undef string "" > Syntax error undef "" string > No statements undef "" "" > last 0 0 "" "" > last 1 1 "" "" > > The "" above could also be undef, but I did not have the time to check > that now. > > But this is from my perl version. In your case for "No statements" the > value for $! and $@ was ^I. Maybe this is a syslog oddity? I've never seen $! or $@ getting set to "^I" ("\t"), so I don't think this is their actual value. > I can provide some testing code to you if you want so we can determine > the table above for your perl version. I doubt it would be any different with Perl 5.8.8, which is what I'm running. Well, we could try setting $! to 0 before the do() call and checking ($! || $@) afterwards. If that doesn't work, then the debarchiver man-page would have to explain that there needs to be a final, true- valued statement in every config file.
signature.asc
Description: This is a digitally signed message part.