One other thing surprised me slightly. Every use of ok I had seen previously uses brackets, but I notice that your examples do not. I have put brackets in for consistency, but is this just cargo cult? If not, what is the effect of using the brackets?

The parenthesis after a subroutine name are another peculiarity of Perl 5 :-)

When perl enounters an identifier like ok in the source code, it can interpret it in two ways: either as a "barword" (a string literal), or as the name of a subroutine.

If perl knows about a subroutine of that name, it decides in favor of the subroutine interpretation, otherwise it chooses the bareword. If you put parenthesis after the identifier, it always chooses the subroutine.

So, the parens are only needed if the subroutine is declared later in the file. Since you use Test::More; (or something similar) at the start of your test file, all the testing routines are immediately imported, and thus known as subroutines.

Here are a few examples of the parsing differences:

$ perl -le 'print STDOUT foo' # bareword foo $ perl -le 'use strict; print STDOUT foo' # strict disables barewords Bareword "foo" not allowed while "strict subs" in use at -e line 1. Execution of -e aborted due to compilation errors. $ perl -e 'use strict; sub foo { }; foo' # works fine $ perl -e 'use strict; foo; sub foo { };' # error, foo is a bareword, +because it's not declared yet Bareword "foo" not allowed while "strict subs" in use at -e line 1. Execution of -e aborted due to compilation errors. $ perl -e 'use strict; foo(); sub foo { };' # that's where you actuall +y need the parens; no error

In reply to Re^3: Testing error handling that calls "die" by moritz
in thread Testing error handling that calls "die" by davies

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.