Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: How can I see a CPAN module's print message

by live4tech (Sexton)
on Jan 06, 2013 at 08:39 UTC ( #1011850=note: print w/replies, xml ) Need Help??

in reply to How can I see a CPAN module's print message

If this code is in a package called "TieRegistry", you will not see the output from print statements outside of any methods (subroutines) in that module just by typing "use TieRegistry"

If the print statements are in a subroutine in the package TieRegistry:

package TieRegistry; use strict; use Carp; sub new { my $class = shift; my $self = bless {}, $class; } sub PrintThis { print "my print message\n"; }

And then in your main program, after "use TieRegistry", you had:

my $test = TieRegistry->new; $test->PrintThis;

The line "my print message" would print.

Replies are listed 'Best First'.
Re^2: How can I see a CPAN module's print message
by anaconda_wly (Scribe) on Jan 06, 2013 at 09:06 UTC
    But why? As I can do it like this:
    use strict; use warnings; { package MyPackage; use Carp; carp "print message"; } 1;
    use MyPackage; &main; sub main { }

      Also consider that Perl will load the first file it finds in @INC. Inspect the values of %INC to find out which file Perl loaded, and which one you edited. See perlvar and Data::Dumper.

      use TieRegistry; print Dumper \%INC;

      That line will print because it's not in a sub. A line inside a sub can only print when that sub is actually executed.

      (The exception to this rule being a line that is evaluated at compile time. But it would be unusual to do this.)

      perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
        Yes, so my print or carp in file scope(I mean not in any sub) should print the message if I "use" it I think.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1011850]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2023-03-27 18:00 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (65 votes). Check out past polls.