What is the ellipsis statement in Perl?

Perl’s ellipsis statement (...) acts as a placeholder for code not yet implemented.

Although Perl parses the ellipsis statement without issue, the Unimplemented exception is thrown if an attempt is made to execute the code.

Syntax

Syntactically, the ellipsis statement is represented using the ...; operator. It can be used in place of any complete statement. The semi-colon (;) can be omitted if the ellipses statement is immediately followed by a closing brace ( } ).

The commands below show the appropriate syntax for invoking the ellipsis statement:

## Method 1
sub thisFunc{ ... }

## Method 2
sub thisFunc{ ...; }

Examples

The code below shows different examples of how the ellipsis statement can be used in Perl:

#!/usr/bin/perl
# unimplemented function
sub funcOne { ... }
# function with two unimplemented statements
sub funcTwo {
print "Inside funcTwo!\n";
...;
{ ... }
}
# placeholder for eval expression
eval { ... };
# catch exception thrown by subroutines
eval { funcOne() };
if ($@ =~ /^Unimplemented/) {
print "Unimplemented Function.\n";
}
eval { funcTwo() };
if ($@ =~ /^Unimplemented/) {
print "Unimplemented Function.\n";
}

Explanation

The code above shows 33 different ways the ... operator can be used as a placeholder for unimplemented statements.

The code defines two subroutines: funcOne and funcTwo. The funcOne subroutine is completely unimplemented with the ... statement as a placeholder for the missing statements. The funcTwo subroutine is partially implemented due to the presence of the print statement. The ... statements in lines 99 and 1010 serve as placeholders for the unimplemented statements of funcTwo.

Perl parses the ... statements in the subroutines and the eval statement without any errors; however, an Unimplemented exception is thrown when the funcOne and funcTwo subroutines are invoked in lines 1717 and 2222, respectively.

Syntax errors

Ellipsis statements cannot be used as placeholders for expressions in larger statements, e.g., if-else statements or mathematical operations. The invalid usage of the ellipsis statement results in a syntax error.

The snippet below shows how syntax errors may arise from the use of the ellipsis statement:


## Placeholder for expression in if-condition
if( $condition && ...){ print "OK"};

## Placeholder for part of mathematical expression
$sum = 5 + ...;

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved