[prev in list] [next in list] [prev in thread] [next in thread] 

List:       perl5-porters
Subject:    Re: [perl #75466] [PATCH] glob is inconsistent about <> overloading
From:       Dave Mitchell <davem () iabyn ! com>
Date:       2010-05-31 13:08:04
Message-ID: 20100531130804.GP3049 () iabyn ! com
[Download RAW message or body]

On Sun, May 30, 2010 at 02:37:15PM -0700, Father Chrysostomos wrote:
> From overload's docs:
> 
> o    Iteration
> 
> "<>"
> 
> If not overloaded, the argument will be converted to a  
> filehandle
> or glob (which may require a stringification).  The same
> overloading happens both for the read-filehandle syntax "< 
> $var>"
> and globbing syntax "<${var}>".
> 
> It hasn't happened with globbing syntax since File::Glob was  
> introduced with 5.6. Actually, it does happen in miniperl and when  
> perl is otherwise compiled with PERL_EXTERNAL_GLOB (how do you do  
> that, BTW?). It can also be triggered in 5.6 with BEGIN { ++$INC{"File/ 
> Glob.pm"} }. The latter crashes as of 5.8, but a patch I've just  
> submitted (75464) fixes that.
> 
> Also, external glob does not respect <> overloading if the overloaded  
> object is returned by a tied scalar.
> 
> So, the docs are wrong most of the time. In a few corner cases they  
> are right.
> 
> I propose that we fix the docs and eliminate this exceptional case,  
> making pp_glob (aka external glob) act the same way as File::Glob.

Personally I think it should be the other way round - we should fix perl
to match the docs. ie the behaviour of '<some_expression>' should be:

    if some_expression is a ref to an overloaded object then call
    the overload iter ('<>') function;
    else if some_expression is a simple scalar etc, call readline;
    else call glob.

That way <> becomes a general overloadable 'iterator' operator which
doesn't stop iterating just because the expression changes a bit.


-- 
print+qq&$}$"$/$s$,$a$d$g$s$@$.$q$,$:$.$q$^$,$@$a$~$;$.$q$m&if+map{m,^\d{0\,},,${$::{$'}}=chr($"+=$&||1)}q&10m22,42}6:17a2~2.3@3;^2dg3q/s"&=~m*\d\*.*g



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic