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

Re: Visualize Perl Program

by davido (Cardinal)
on Sep 25, 2020 at 19:46 UTC ( #11122214=note: print w/replies, xml ) Need Help??


in reply to Visualize Perl Program

B::Xref (lanx beat me to mentioning it; I was fiddling with a POC).

#!/usr/bin/env perl my $fb = fizzbuzz(); print "$_\n" for @$fb; sub fizzbuzz { my ($n, $m) = (1, 100); my @out; for my $num ($n .. $m) { my $line = ''; $line .= 'fizz' if $num % 3 == 0; $line .= 'buzz' if $num % 5 == 0; push @out, $line || $num; } return \@out; }

When you run this with B::Xref you get the following:

perl -MO=Xref mytest.pl File mytest.pl Subroutine (definitions) Package Internals &SvREADONLY s0 &SvREFCNT s0 &V s0 &getcwd s0 &hv_clear_placeholders s0 Package PerlIO &get_layers s0 Package Regexp &DESTROY s2147483647 Package Tie::Hash::NamedCapture &CLEAR s0 &DELETE s0 &EXISTS s0 &FETCH s0 &FIRSTKEY s0 &NEXTKEY s0 &SCALAR s0 &STORE s0 &TIEHASH s0 &_tie_it s0 &flags s0 Package UNIVERSAL &DOES s0 &VERSION s0 &can s0 &isa s0 Package constant &_make_const s0 Package main &fizzbuzz s3 Package mro &method_changed_in s0 Package re &is_regexp s0 &regexp_pattern s0 &regname s0 &regnames s0 &regnames_count s0 Package version &("" s0 &() s0 &(* s0 &(*= s0 &(+ s0 &(+= s0 &(- s0 &(-= s0 &(/ s0 &(/= s0 &(0+ s0 &(<=> s0 &(abs s0 &(bool s0 &(cmp s0 &(nomethod s0 &_VERSION s0 &boolean s0 &declare s0 &is_alpha s0 &is_qv s0 &new s0 &noop s0 &normal s0 &numify s0 &parse s0 &qv s0 &stringify s0 &vcmp s0 Subroutine (main) Package (lexical) $fb i3, 4 @$fb 4 Package main $_ 4 &fizzbuzz &3 Subroutine fizzbuzz Package (lexical) $line i10, 13 $m i7, 9 $n i7, 9 $num 11, 12, 13 @out i8, 13, 15 mytest.pl syntax OK

The numbers you see all over the place are where some entity appears. So $line first appears on line 10, and again on line 13, for example. As you layer in other modules such as strict, warnings, or others that are actually substantial, the output grows considerably. But things are fairly well categorized, so if you know what package to look within, you'll find what you're after. I actually removed use strict and use warnings just to produce output that was more useful in this post.


Dave

Replies are listed 'Best First'.
Re^2: Visualize Perl Program
by aartist (Pilgrim) on Sep 25, 2020 at 20:11 UTC
    Wow, discovered a gem here. I had no idea, why I had not taken care to ask/know this earlier.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2021-01-25 18:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?