Help for this page

Select Code to Download


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