Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Help Changing use into require/import

by Anonymous Monk
on Mar 11, 2018 at 09:36 UTC ( #1210645=note: print w/replies, xml ) Need Help??


in reply to Help Changing use into require/import

capture { system qq[ echo Hello, World | cat ]; }

Can't call method "capture" without a package or object reference

Hypothesis (untested): if you do Capture::Tiny::->import("capture"); at BEGIN time, like use does, Perl knows the prototype of the capture function (which contains & and makes it accept blocks which are really anonymous subroutines without sub keyword). If you do the import at runtime, the subroutine is still imported (you can call it without fully qualifying Capture::Tiny::capture), but it's too late for Perl parser to change its understanding of your code: instead of capture(sub{...}), it sees {...}->capture and fails.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1210645]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2018-04-20 22:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?