I've a ghastly feeling that this is something blatantly obvious. Unfortunately I've got nobody here to tell me what exactly and the rubber duck has been surprisingly unhelpful.

Can anybody tell me why with this code:

#! /usr/bin/perl use strict; use warnings; { package SomePackage; use Exporter 'import'; our @EXPORT = ( 'hello' ); sub hello (&) { print "hello\n" } # works with the prototype inside the package hello { die "should not be called" } } SomePackage->import( 'hello' ); # works outside the package with a fully qualified name SomePackage::hello { die "should not be called" }; # works outside the package if we ignore prototypes hello( sub { die "should not be called" } ); # perl does know what the prototype is print "prototype is ", prototype \&hello, "\n"; # and yet... hello { die "should not be called" };

that last call to hello() is parsed as:

do { die 'should not be called' }->hello;

rather than as a call to SomePackage::hello

I'm off to the library and to get some coffee. Hopefully somebody will demonstrate where I'm being dim by the time I get back :-)


In reply to Odd behaviour with prototypes and Exporter by adrianh

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.