in reply to Re: Hash assignment: Undocumented feature?
in thread Hash assignment: Undocumented feature?

(Oops. Didn't really need to dash off, on second thought.) I slightly suspect your example is more complex than I can deal with. What I meant is simply something like this (and I think it does not matter if the values are simple scalars or references to something complex):

%what_all_workers_have = ( holidays => 30, hours_per_week => 40, office_space => 10, job_title => "Clerk", ); ## turning to John, who is a wheelchair user: %what_john_has = ( %what_all_workers_have, office_space => 20, # needs room to maneuvre hours_per_week => 35, # needs more breaks );

One needn't even worry if %workers_have actually contains the keys office_space and hours_per_week. It will either add or overwrite them, whichever is required. To me, this seems quite elegant and time-saving. In any case, it's less code to type than any other version I could think of.

Replies are listed 'Best First'.
Re^3: Hash assignment: UndERDocumented feature?
by AnomalousMonk (Archbishop) on Aug 11, 2013 at 17:53 UTC
    %what_john_has = ( %what_all_workers_have, office_space => 20, # needs room to maneuvre hours_per_week => 35, # needs more breaks );

    That's kinda like what
        my %arguments = (%$hr_defaults, %{ $hr_args || {} });
    is doing in my example code: as you've written,  %what_all_workers_have is the default of what a particular worker has.