Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
The scoping of 'use Carp' and 'use strict' is the same. The problem was that your code didn't use the effects of 'use Carp'. The following compiles:
use strict; use warnings; use Carp qw(croak); package Test; sub croak_test { Carp::croak "this is a test"; } Test::croak_test;
You were calling Test::croak, which doesn't exist, so the parser sees no reason to accept an unparenthesized string constant after it.

So use Carp qw(croak) must be declared after the 'package' only so that will create the function you're actually trying to call. It could go earlier, if you wish: you could insert

{ package Test; use Carp qw(croak); }
at any point before the 'package', and it would create the correct subroutine and allow you to call it without parens. Heck, you could just put sub Test::croak; at any point in the file before the call to croak and it would be happy.

(Well, if you don't define the function, it'll complain if you ever try to call Test::croak, but at least it'll compile.)


In reply to Re: Use of Carp outside of package won't compile... by sfink
in thread Use of Carp outside of package won't compile... by memnoch

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (1)
As of 2024-04-19 18:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found