#!/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
®exp_pattern s0
®name s0
®names s0
®names_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.
|