http://www.perlmonks.org?node_id=1011838

anaconda_wly has asked for the wisdom of the Perl Monks concerning the following question:

##Hi, happy new year perl monks! 1. I had add print message in a CPAN's module. But I didn't see any in output. Did they redirect it to somewhere else? 2. I see croak and carp used in a CPAN module. I add some in my code to display some message. But when I run, I didn't see any on screen, why Thanks! ##

Yes, as roboticus said, one error. I modified my question as this:

I want to trace the process of a module, say TieRegistry. So I add some print messge to it. For simple like below:

use vars qw( $RegObj %_Roots %RegHash $Registry ); carp "my print message\n ";#no print print "my print message\n ";#no print

The two lines are in a global place out of any function. So I think in my code, it will print the messages at the place of use, right?

use TieRegistry
I didn't see either of them.

Replies are listed 'Best First'.
Re: How can I see a CPAN module's print message
by roboticus (Chancellor) on Jan 06, 2013 at 07:37 UTC

    1) maybe

    2) you're doing it wrong.

    Seriously, though, how do you expect us to be able to tell you what you did wrong without you showing us what you did?

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re: How can I see a CPAN module's print message
by live4tech (Sexton) on Jan 06, 2013 at 08:39 UTC

    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.

      But why? As I can do it like this: MyPackage.pm
      use strict; use warnings; { package MyPackage; use Carp; carp "print message"; } 1;
      main.pl
      use MyPackage; &main; sub main { }

        Also consider that Perl will load the first file TieRegistry.pm 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'
Re: How can I see a CPAN module's print message
by live4tech (Sexton) on Jan 06, 2013 at 07:34 UTC

    Please provide code. Very difficult to help if we cannot see what you are referring to.

Re: How can I see a CPAN module's print message
by Anonymous Monk on Jan 06, 2013 at 07:49 UTC
    Why are you editing CPAN.pm, what problem are you trying to solve?