in reply to Use of Carp outside of package won't compile...
You were calling Test::croak, which doesn't exist, so the parser sees no reason to accept an unparenthesized string constant after it.use strict; use warnings; use Carp qw(croak); package Test; sub croak_test { Carp::croak "this is a test"; } Test::croak_test;
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
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.{ package Test; use Carp qw(croak); }
(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.)
|
|---|