{
    "mode": "perldoc",
    "parameter": "B::Xref",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/B%3A%3AXref/json",
    "generated": "2026-06-03T10:10:46Z",
    "synopsis": "perl -MO=Xref[,OPTIONS] foo.pl",
    "sections": {
        "NAME": {
            "content": "B::Xref - Generates cross reference reports for Perl programs\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "perl -MO=Xref[,OPTIONS] foo.pl\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "The B::Xref module is used to generate a cross reference listing of all definitions and uses of\nvariables, subroutines and formats in a Perl program. It is implemented as a backend for the\nPerl compiler.\n\nThe report generated is in the following format:\n\nFile filename1\nSubroutine subname1\nPackage package1\nobject1        line numbers\nobject2        line numbers\n...\nPackage package2\n...\n\nEach File section reports on a single file. Each Subroutine section reports on a single\nsubroutine apart from the special cases \"(definitions)\" and \"(main)\". These report,\nrespectively, on subroutine definitions found by the initial symbol table walk and on the main\npart of the program or module external to all subroutines.\n\nThe report is then grouped by the Package of each variable, subroutine or format with the\nspecial case \"(lexicals)\" meaning lexical variables. Each object name (implicitly qualified by\nits containing Package) includes its type character(s) at the beginning where possible. Lexical\nvariables are easier to track and even included dereferencing information where possible.\n\nThe \"line numbers\" are a comma separated list of line numbers (some preceded by code letters)\nwhere that object is used in some way. Simple uses aren't preceded by a code letter.\nIntroductions (such as where a lexical is first defined with \"my\") are indicated with the letter\n\"i\". Subroutine and method calls are indicated by the character \"&\". Subroutine definitions are\nindicated by \"s\" and format definitions by \"f\".\n\nFor instance, here's part of the report from the *pod2man* program that comes with Perl:\n\nSubroutine clearnoremap\nPackage (lexical)\n$readytoprint   i1069, 1079\nPackage main\n$&                1086\n$.                1086\n$0                1086\n$1                1087\n$2                1085, 1085\n$3                1085, 1085\n$ARGV             1086\n%HTMLEscapes     1085, 1085\n\nThis shows the variables used in the subroutine \"clearnoremap\". The variable $readytoprint is\na my() (lexical) variable, introduced (first declared with my()) on line 1069, and used on line\n1079. The variable $& from the main package is used on 1086, and so on.\n\nA line number may be prefixed by a single letter:\n\ni   Lexical variable introduced (declared with my()) for the first time.\n\n&   Subroutine or method call.\n\ns   Subroutine defined.\n\nr   Format defined.\n\nThe most useful option the cross referencer has is to save the report to a separate file. For\ninstance, to save the report on *myperlprogram* to the file *report*:\n\n$ perl -MO=Xref,-oreport myperlprogram\n",
            "subsections": []
        },
        "OPTIONS": {
            "content": "Option words are separated by commas (not whitespace) and follow the usual conventions of\ncompiler backend options.\n\n\"-oFILENAME\"\nDirects output to \"FILENAME\" instead of standard output.\n\n\"-r\"    Raw output. Instead of producing a human-readable report, outputs a line in\nmachine-readable form for each definition/use of a variable/sub/format.\n\n\"-d\"    Don't output the \"(definitions)\" sections.\n\n\"-D[tO]\"\n(Internal) debug options, probably only useful if \"-r\" included. The \"t\" option prints\nthe object on the top of the stack as it's being tracked. The \"O\" option prints each\noperator as it's being processed in the execution order of the program.\n",
            "subsections": []
        },
        "BUGS": {
            "content": "Non-lexical variables are quite difficult to track through a program. Sometimes the type of a\nnon-lexical variable's use is impossible to determine. Introductions of non-lexical non-scalars\ndon't seem to be reported properly.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Malcolm Beattie, mbeattie@sable.ox.ac.uk.\n",
            "subsections": []
        }
    },
    "summary": "B::Xref - Generates cross reference reports for Perl programs",
    "flags": [],
    "examples": [],
    "see_also": []
}