develooper Front page | perl.perl5.porters | Postings from November 2007

Re: [perl #46987] OO-call failures, autoviv-functions & testingtheir existence

Thread Previous
From:
Josh Jore
Date:
November 1, 2007 17:45
Subject:
Re: [perl #46987] OO-call failures, autoviv-functions & testingtheir existence
Message ID:
20071102004522.GB25954@grenekatz.org
On Thu, Nov 01, 2007 at 10:08:58PM +0100, Dr.Ruud wrote:
} Linda W schreef:
} 
} >      I would prefer Perl, continue to strive to be the (*usually*)
} > user-friendly language that it is, and try to do what the user
} > might have really been intending before throwing a fatal error.
} 
} What do you think that "return \%data{@keys}" means? It pretty much
} looks to me like the user wants to return a reference to a hash slice.
} To make it sort of work, you could write it like I show below, but that
} involves copying, which might not be what the user wanted:
} 
}     my %tmp;
}     @tmp{@keys} = @data{@keys};
}     return \%tmp;

To get what you want requires trickery. It's an array reference where
the elements are aliased back to the values in %data.

return sub { \@_ }->( @data{@keys } );

-- 
Josh

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About