# man > B::Xref(3perl)

---
type: CommandReference
command: B::Xref
mode: perldoc
section: 3perl
source: perldoc
---

## Quick Reference

- `perl -MO=Xref foo.pl` — Generate cross reference report to stdout
- `perl -MO=Xref,-oreport foo.pl` — Save report to file 'report'
- `perl -MO=Xref,-r foo.pl` — Raw machine-readable output
- `perl -MO=Xref,-d foo.pl` — Omit '(definitions)' sections

## Name

B::Xref - Generates cross reference reports for Perl programs

## Synopsis

shell
perl -MO=Xref[,OPTIONS] foo.pl
## Description

The B::Xref module generates a cross reference listing of all definitions and uses of variables, subroutines, and formats in a Perl program. The report is organized by file, then subroutine (including special entries "(definitions)" and "(main)"), then package (with "(lexicals)" for lexical variables). Each object name includes its type character(s). Lexical variables include dereferencing information.

Line numbers may be prefixed by a single letter:

- `i` — Lexical variable introduced (declared with `my`)
- `&` — Subroutine or method call
- `s` — Subroutine defined
- `r` — Format defined

Simple uses have no prefix.

## Options

- `-oFILENAME` — Direct output to FILENAME instead of standard output.
- `-r` — Raw output. Outputs machine-readable lines for each definition/use.
- `-d` — Don't output the "(definitions)" sections.
- `-D[tO]` — Internal debug options (only useful with `-r`). 't' prints the object on the top of the stack; 'O' prints each operator as processed.

## Bugs

Non-lexical variables are difficult to track. Sometimes the type of use for a non-lexical variable is impossible to determine. Introductions of non-lexical non-scalars are not reported properly.

## Examples

Generate a cross reference report and save to file:

shell
perl -MO=Xref,-oreport myperlprogram
Example report output (from perl's pod2man):

text
Subroutine clear_noremap
  Package (lexical)
    $ready_to_print   i1069, 1079
  Package main
    $&                1086
    $.                1086
    $0                1086
    $1                1087
    $2                1085, 1085
    $3                1085, 1085
    $ARGV             1086
    %HTML_Escapes     1085, 1085
