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

Re: Use of Carp outside of package won't compile...

by sfink (Deacon)
on Dec 20, 2007 at 05:22 UTC ( #658066=note: print w/replies, xml ) Need Help??

in reply to Use of Carp outside of package won't compile...

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.)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://658066]
[ovedpo15]: my code checks the value after that comma, if it isn't valid it will remove it. so I would like to remove the substring after that comma meaning getting the string before comma.
[hippo]: Are you sure that Text::CSV_XS isn't already installed at your work? It's such a useful module that it might well be there.
[marto]: pointing out the advantages of cpan modules is well worth in, as both developer and $client/$company benefit greatly
[Tux]: $src =~ m{^(.*),(.*)$/ and $2 !~ $valid and $src = $1;
[Tux]: s,/,},

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (9)
As of 2018-05-27 10:51 GMT
Find Nodes?
    Voting Booth?