Hi Julian

On Sun, Sep 23, 2007 at 03:12:05PM +0000, Julian Mehnle wrote:
> Ola Lundqvist wrote:
> > On Sun, Sep 23, 2007 at 11:49:36AM +0000, Julian Mehnle wrote:
> > > So I think debarchiver should check $! and $@ rather than the result
> > > of do() ("unless ($t)"), which really says nothing about whether the
> > > file could be read and compiled successfully, UNLESS you require
> > > every configuration file to end with a true-valued statement (which
> > > the debarchiver man-page says nothing about).  And I would not make
> > > such a requirement.  Checking $! and $@ should do just fine.
> >
> > The problem here is that $! $@ can contain quite different values, as
> > you noticed... I do not know if perl actually requires the file to end
> > with a true statement or not. Maybe it does. I have not checked the
> > documentation for that.
> 
> `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.

> 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. This means that if I would rely on that
$! and $@ is the empty string, it would have failed in your case
anyway.

I can provide some testing code to you if you want so we can determine
the table above for your perl version.

Best regards,

// Ola

-- 
 --------------------- Ola Lundqvist ---------------------------
/  [EMAIL PROTECTED]                     Annebergsslingan 37      \
|  [EMAIL PROTECTED]                     654 65 KARLSTAD          |
|  http://opalsys.net/                 +46 (0)70-332 1551       |
\  gpg/f.p.: 7090 A92B 18FE 7994 0C36  4FE4 18A1 B1CF 0FE5 3DD9 /
 ---------------------------------------------------------------



-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to