# Both have the following pragmas in place: #!/usr/bin/perl -w use strict; use Carp; #================================================= #Version 1: no extra variable (slightly confusing) #================================================= # Get the keys of @_ foreach (keys %{ +{ @_ } }) { # Check to see if a key has a leading underscore ($self->{"_$_"} = ${ +{@_} }{$_}),next if (exists $self->{"_$_"}); # Check to see if a key has no leading underscore (exists $self->{$_}) ? $self->{$_} = ${ +{@_} }{$_} : # Warn the user if the key isn't valid carp "The entry $_ is not a valid key.\n"; } #================================ # Version 2: a spare %tmp to help #================================ # Get the keys of @_ my %tmp = ( @_ ); foreach (keys %tmp) { # Check to see if a key has a leading underscore ($self->{"_$_"} = $tmp{$_}),next if exists $self->{"_$_"}; # Check to see if a key has no leading underscore (exists $self->{$_}) ? $self->{$_} = $tmp{$_} : # Warn the user if the key isn't valid carp "The entry $_ is not a valid key.\n"; }