in reply to how to get out of subroutine without returning anything

I think I got it. You want to replace
$schema->resultset("UserScenario")->update_or_create( { name => $user_scenario->{name}, description => $user_scenario->{description}, }, { key => "u_user_scenario_name" }, );
with
$schema->resultset("UserScenario")->update_or_create( { name => $user_scenario->{name}, }, { key => "u_user_scenario_name" }, );
when $user_scenario->{description} is "empty". First, what do you mean by "empty"? Scalars can't be empty. Empty string? Undef? Or since the scalar question in a hash element, non-existent? I'm going to assume "empty" means "undefined or non-existent".

The straightforward approach:

if (defined($user_scenario->{description}) { $schema->resultset("UserScenario")->update_or_create( { name => $user_scenario->{name}, description => $user_scenario->{description}, }, { key => "u_user_scenario_name" }, ); } else { $schema->resultset("UserScenario")->update_or_create( { name => $user_scenario->{name}, }, { key => "u_user_scenario_name" }, ); }

Something more compact:

$schema->resultset("UserScenario")->update_or_create( { name => $user_scenario->{name}, ( defined($user_scenario->{description}) ? ( description => $user_scenario->{description} ) : () ), }, { key => "u_user_scenario_name" }, );

That's not very readable. How about

my %fields; $fields{name} = $user_scenario->{name}; $fields{description} = $user_scenario->{description} if defined($fields{description}); $schema->resultset("UserScenario")->update_or_create( \%fields, { key => "u_user_scenario_name" }, );

Replies are listed 'Best First'.
Re^2: how to get out of subroutine without returning anything
by shmem (Chancellor) on Mar 30, 2010 at 16:13 UTC

    A bit more compact and nearly readable -

    $schema->resultset("UserScenario")->update_or_create( { name => $user_scenario->{name}, ( description => $user_scenario->{description} ) x!! $user_scenari +o->{description}, }, { key => "u_user_scenario_name" }, );

    - if it wasn't for the "Highlander's List Asserter" (x!!) "secret operator", which Aristotle presented as the "boolean list squash operator" ;-)