List Info

Thread: Re: filetests sometimes do not set _




Re: filetests sometimes do not set _
user name
2007-10-21 16:47:32
* Nicholas Clark (nickccl4.org) [071021 20:53]:
> On Wed, Oct 17, 2007 at 10:22:58AM +0200, Mark Overmeer
wrote:

> > Apparently, -r/-w/-x/-R/-W/-X implemented in
filetest to not
> > set '_' anymore, where they did so in perl5.8.8
> 
> On Fri, Oct 19, 2007 at 02:20:26AM +0200, Andreas J.
Koenig wrote:
> >     Change 19392 by jhikosh on 2003/05/03
05:33:04
> >         Salvage 'use filetest "access"'
from compiletime to runtime.
> 
> It seems that Jarkko actually fixed a bug here - I'd
infer that access()
> wasn't being called when it was expected that it would
be.

Oh, that's a good reason for that patch, and does explain
things.

> I don't believe that the current behaviour is a
behavioural bug.
> The documentation could be clearer, however.
> 
> It is documented that _ is set to the last stat.
> It is documented that under filetest, -r/-w/-x/-R/-W/-X
use access() rather
> than the mode bits from the file.

Well, perldoc -f stat says:

  if "stat" is passed the special filehandle
consisting of an
  underline, no stat is done, but the current contents of
the
  stat structure from the last "stat",
"lstat", or filetest are
  returned. 

I do read "filetest" here... (perl5.10.0)

> Hence one does not need to call stat(), so perl does
not. *That*
> implementation efficiency is not documented.

On many places, Perl prefers qualilty over performance.  I
would even
say that 'use filetest' should be the default on all
platforms which
support it (which support ACLs).

That file test behavioral change when 'use filetest' is
given somewhere
else in the file is at least very unexpected and
error-prone.

On the other hand, the whole use of -w / -r /-x should be
avoided in
general: open to write and handle the failure otherwise you
get into
race conditions.  So, the actual number of access()/stat()
doubles in
good code should be minimal... I have such a rare case where
I need to
use -r (I think), because I am checking the filesystem
structure.

> So I think that the current behaviour is preferable. If
we changed it so that
> -r/-w/-x/-R/-W/-X also call stat() as well as access(),
then we give everyone
> inefficiency that they can't avoid. Whereas the current
behaviour is merely
> caveat emptor on anyone wishing to take advantage of
the _ filehandle.
> 
> I'm curious - on a modern Unix system with decent OS
caching, how much does
> not calling stat again really save?

Probably only an extra context switch.  (Do you known how
many a simple
'use' makes?)
-- 
Regards,
               MarkOv

------------------------------------------------------------
------------
       Mark Overmeer MSc                               
MARKOV Solutions
       MarkOvermeer.net                          solutionsovermeer.net
http://Mark.Overmeer.net
                  http://solutions.overme
er.net


[1]

about | contact  Other archives ( Real Estate discussion Medical topics )