paperlined.org
dev > perl
document updated 7 days ago, on Feb 13, 2025

examining other code's objects, in Perl

general advice

Use Data::Printer instead of Data::Dumper. It's worth installing.

If you want to display Data::Printer's data to the browser, HTML::FromANSI::Tiny has worked much better for me than HTML::FromANSI has.

I have a variable, tell me everything about it

ref( $var )

If $var is a blessed object, ref() returns the name of the class that it was blessed as.

Else if $var is a reference to an array/hash/etc, it returns a string of what type it refers to.

Otherwise, if it's not a reference (i.e. it's a scalar), it returns the empty string.

The official manual says that ref()'s output is confusing, and you should instead use either Scalar::Util::blessed() or Scalar::Util::reftype(), depending on which you're looking for.

I have a variable that I want to access, but it seems inaccessible (e.g. a lexical variable)

TODO: maybe use B::Showlex?

I want to list all variables available in a specific area

Symbol tables. TODO: Oh god, this is a morass. Is there any quick and easy [2] ways to use them?