in reply to Evil bug: map + anony hash

It might be a problem with $_ localization: look at line 3.

package Car; sub new { bless {},shift }; sub title { $_='title'; 'BITTER' }; sub descr { 'BUTTER' }; sub F { ( Car->new, Car->new, Car->new, Car->new ) }; package main; print map{{title=>$_->title(),desc=>$_->descr()}} Car->F(); use Data::Dumper; die Dumper map{{title=>$_->title(),desc=>$_->descr()}} Car->F();

output:

Can't locate object method "descr" via package "title" (perhaps you forgot to load "title"?) at test.pl line 8.

Replies are listed 'Best First'.
Re: Re: Evil bug: map + anony hash
by BUU (Prior) on Sep 24, 2002 at 21:10 UTC
    BING BING BING!! We have a winner! That was exactly the problem (and solution) i rewrote the methods that were being called to avoid using $_, and it worked like a charm. Hmph, that has to be a bug or something.

      Oh. That's not a bug - $_ is a global so if you stomp on it then you have to deal with it. The thing is - since $_ is a global just local()ize it and it'll lose your stomping.

        Well, i would just expect map{} to have its own localized $_, and restore the value of it after a call out. Or something. I'm guess i'm just so used to DWIM'ery that it caught me off guard.