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

Hi all, I am used to execute perl scripts, but not to the interactive console (debug mode) I just discovered ( perl -d -e 1). Say that I defined the global variable: $age=25; I can print the variable content with print($age);. But is there any simpler way? Thanks

Replies are listed 'Best First'.
Re: print variable content
by Eily (Monsignor) on Sep 06, 2016 at 08:18 UTC

    There's the p command that simply prints your variable as print would do. Or x that displays the content of the variable, nested structures included. You can find those commands by typing h in the console. And you can learn more about the debugger in the corresponding documentation and tutorial.

    Edit: Thanks to haukex and johngg for pointing out that I gave two links to perldebug instead of one to perldebtut :).

      Thanks, that's exactly what I needed. Cheers.
Re: print variable content
by haukex (Archbishop) on Sep 06, 2016 at 08:19 UTC

    Hi dovah,

    print is pretty much the simplest way to print a variable*. It is printed to the currently selected output handle.

    What is your goal? Do you want the output to look a certain way, or the code to look or act a certain way?

    There are modules to output the contents of complex variables / data structures, for example Data::Dump, as follows. Note the pp function by itself prints to STDERR instead of STDOUT, if you want the latter, you have to use print pp ....

    use Data::Dump 'pp'; my $age = 25; pp $age; pp { foo => "bar" }; __END__ 25 { foo => "bar" }

    There's also the core module Data::Dumper, which provides similar functionality.

    * Update: Oh, oops, I see, you're asking about the debugger. Then Eily's response is more on point.

    Hope this helps,
    -- Hauke D