Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Question about ellipsis statement '...'

by rsFalse (Hermit)
on Mar 01, 2021 at 10:13 UTC ( #11128939=perlquestion: print w/replies, xml ) Need Help??

rsFalse has asked for the wisdom of the Perl Monks concerning the following question:

Hello,
I tried to use examples of ellipsis '...' provided by documentation https://perldoc.perl.org/perlsyn#The-Ellipsis-Statement. But I found description not clearly written. And I'm not sure if I got correct behavior of '...', because it is "documented" in a way (cite): "These examples show how the ellipsis works:". But there are no outputs of examples provided.
I don't understand why '...; print 1;' exits after ellipsis and not proceeds to print (v5.28). Can someone explain?
I understand why 'print ...' breaks: because it makes syntax error.

Replies are listed 'Best First'.
Re: Question about ellipsis statement '...'
by Corion (Pope) on Mar 01, 2021 at 10:36 UTC

    Good spot!

    I think the ellipsis "keyword" can be best explained as being equivalent to

    die "Unimplemented";

    Edit: And the documentation says at the end of the first paragraph:

    Perl throws an exception with the text Unimplemented
      For me was unclear what does mean "throws an exception". Kinda vegetable I am unfamiliar with.
        Refer to perl's glossary (perlglossary) for 'exception' and 'exception handling'.
        Bill
Re: Question about ellipsis statement '...'
by shmem (Chancellor) on Mar 01, 2021 at 14:58 UTC

    There are two uses for '...' - as:

    1. part of an expression - see Range Operators
    2. statement on its own - equivalent to die "Unimplemented"; - see The Ellipsis Statement

    And so...

    I don't understand why '...; print 1;' exits after ellipsis and not proceeds to print (v5.28). Can someone explain?

    The sequence ...; print 1; does not proceed to print, because it dies before the print, just at the ...;

    I understand why 'print ...' breaks: because it makes syntax error.

    Yes. Because it is not a statement on its own, it is interpreted as the infix range operator, which lacks arguments - so "syntax error".

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
Re: Question about ellipsis statement '...'
by GrandFather (Saint) on Mar 01, 2021 at 20:06 UTC

    I sometimes use an ellipsis statement in example code to indicate "stuff goes here" and "this is not executable". In the example that branch of the code is not expected to be executed.

    I sometimes use an ellipsis in code I am writing to say "work needed here" and to give me a sharp whack upside of the head if that branch of the code does get executed. In a test environment exception handling can detect unimplemented code that way and report it so appropriate tests can be written that will fail with a useful message until the code is implemented.

    Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
Re: Question about ellipsis statement '...' (ToDo marks)
by LanX (Cardinal) on Mar 01, 2021 at 20:26 UTC
    It would be interesting to know which behavior you rather wanted/expected.

    If it's just a no-op, try triple semi-colons as visual indicator

    ;;;

    or a comment

    #TODO yadda yadda

    If you want a warning instead of a die you could define your own sub __todo__

    use strict; use warnings; use Data::Dump qw/pp dd/; package BLA; # poor mans import BEGIN { *__todo__ = \&TODO::__todo__; } sub add { my ( $arg1,$arg2 ) = @_ ; __todo__ "check argument type"; return $arg1+$arg2; } add 1,2; # other module package TODO; use Carp; sub __todo__ { carp "TODO: $_[0]"; }

    TODO: check argument type at d:/tmp/pm/t_carp.pl line 17.

    update

    improved demo with packages

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://11128939]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2021-04-22 11:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?