Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I've got some weirdness I don't understand when I load a module with Test::More's use_ok()

I was using an array-reference prototype to pass an array by reference without the module user having to fuss about it -- but when I load the module with Test::More's use_ok() all the prototypes seem to be getting ignored.

What is it I'm missing ?

Here's a cut-down example module,

package CST2; use strict; use warnings; use Exporter; our @ISA = qw(Exporter); our @EXPORT = qw(ArrayCount); sub ArrayCount(\@) { (my $array_Ref, undef) = @_; my $ct; foreach my $element (@{$array_Ref}) { $ct++ } $ct; } 1;
and a calling script,
#!/usr/bin/perl use strict; use warnings; use Test::More; #BEGIN:{ use_ok('CST2'); } use CST2; my @patternList = qw(one two three); my $count = ArrayCount(@patternList); print "$count\n";

With use CST2 everything works fine.

But if I change to BEGIN:{ use_ok('CST2'); }, then I get an error: 'Can't use string ("one") as an ARRAY ref while "strict refs" in use at line 12.'

To make the error go away, I have to change the call in the script to explicitly pass a reference my $count = ArrayCount(\@patternList);

Why is this happening? What is it I've missed, and should have done differently?

For what it's worth, perl --version tells me I'm running perl 5, version 14, subversion 2 (v5.14.2) built for cygwin-thread-multi-64int (with 7 registered patches, see perl -V for more detail); and it's version 0.98 of Test::More

Thanks in advance,


In reply to Prototypes being ignored with use_ok() from Test:More ? by JPMH

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    [Corion]: marto: Ow :(
    [marto]: Corion, not to worry, it was ok :)
    [Corion]: I "just" had a call from a friend whom I host the website for, and they were quite hectic yet uninformed about what they'd have to change for GDPR... This felt like work to me, but at least I got that call in a café, not in the office
    [Corion]: But hopefully today I'll be a bit calmer and call them and update their website with what little they need to change for GDPR. Having a "business front page" as website means you collect and handle very little PII ;)
    [marto]: I've yet to do my mandatory training, GDPR is purely focused at businesses?
    [marto]: there's just so much FUD
    [choroba]: we had the training yesterday
    [hippo]: GDPR applies to everyone but there is an exception for individuals keeping records of their own personal activities.

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (6)
    As of 2018-05-22 07:55 GMT
    Find Nodes?
      Voting Booth?