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.
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{ ...; }
The code below shows different examples of how the ellipsis statement can be used in Perl:
#!/usr/bin/perl# unimplemented functionsub funcOne { ... }# function with two unimplemented statementssub funcTwo {print "Inside funcTwo!\n";...;{ ... }}# placeholder for eval expressioneval { ... };# catch exception thrown by subroutineseval { funcOne() };if ($@ =~ /^Unimplemented/) {print "Unimplemented Function.\n";}eval { funcTwo() };if ($@ =~ /^Unimplemented/) {print "Unimplemented Function.\n";}
The code above shows 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 and 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 and , respectively.
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