then print statements will behave differently when running testing than when run as a module, if the consumer using your code isn’t using such a switch.

Only if the module uses print. And I consider this to be exactly as I want it.

If modules want to use $\, or any other global variable, then they *must* localise and set it. The main program *always* own the globals. So if modules want predictable behaviour from their use of globals, they must localise and set to their requirements.

If my modules need to print to a predefined (global) filehandle, and I want $\ = "\n", then I will localise and set it so either on a case by case basis, or more likely, for (say) debug purposes, I define a private debug function that does so and call that rather than print.

But, most modules don't print directly to STDOUT or STDERR. We'd mostly be pissed off if they did.

Test scripts frequently do print stuff, and when the module is run as a script for testing, the -l is in force.

As for -s, I frequently use runtime configuration in my test scripts like our $MAX //= 1e6;. Then if I want to run a quick test, I can use

perl fred.pm -MAX=1e3

Silly eg:

#! perl -slw use strict; package fred; sub new { my $class = shift; return bless { @_ }, $class; } sub method { my $self = shift; return keys %{ $self }; } return 1 if caller; package main; our $MAX //= 10; print 'Max: ', $MAX; my $o = fred->new( 'a' .. 'z' ); print for $o->method; __END__ C:\test>perl -s fred.pm -MAX=123 Max: 123 w e a m s y u c k q g i o

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^3: 'use' inside or outside of package declaration? by BrowserUk
in thread 'use' inside or outside of package declaration? by John M. Dlugosz

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.