my $class =
$type == 0 ? 'ClassA' :
$type == 1 ? 'ClassB' :
'ClassC';
my $obj = $class->new( foo => 1, bar => 2 );
####
my %args = ( foo => 1, bar => 2 );
my $class =
$type == 0 ? ClassA->new( %args ) :
$type == 1 ? ClassB->new( %args ) :
'ClassC';
##
##
my $class;
given $type {
when 0 { $class = ClassA }
when 1 { $class = ClassB }
default { $class = ClassC }
}
my $obj = $class.new( foo => 1, bar => 1 );
##
##
my @args = ( foo => 1, bar => 1 );
my $obj;
given $type {
when 0 { $obj = ClassA.new( |@args ) }
when 1 { $obj = ClassB.new( |@args ) }
default { $obj = ClassC.new( |@args ) }
}