Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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


In reply to Re: Visualize Perl Program by davido
in thread Visualize Perl Program by aartist

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-25 19:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found