{
    "mode": "perldoc",
    "parameter": "foo",
    "section": "-q",
    "url": "https://www.chedong.com/phpMan.php/perldoc/foo/json",
    "generated": "2026-06-15T14:35:32Z",
    "sections": {
        "Found in /usr/share/perl/5.34/pod/perlfaq5.pod": {
            "content": "How can I set up a footer format to be used with write()?\nThere's no builtin way to do this, but perlform has a couple of\ntechniques to make it possible for the intrepid hacker.\n\nWhy can't I use \"C:\\temp\\foo\" in DOS paths? Why doesn't `C:\\temp\\foo.exe` work?\nWhoops! You just put a tab and a formfeed into that filename! Remember\nthat within double quoted strings (\"like\\this\"), the backslash is an\nescape character. The full list of these is in \"Quote and Quote-like\nOperators\" in perlop. Unsurprisingly, you don't have a file called\n\"c:(tab)emp(formfeed)oo\" or \"c:(tab)emp(formfeed)oo.exe\" on your legacy\nDOS filesystem.\n\nEither single-quote your strings, or (preferably) use forward slashes.\nSince all DOS and Windows versions since something like MS-DOS 2.0 or so\nhave treated \"/\" and \"\\\" the same in a path, you might as well use the\none that doesn't clash with Perl--or the POSIX shell, ANSI C and C++,\nawk, Tcl, Java, or Python, just to mention a few. POSIX paths are more\nportable, too.\n",
            "subsections": []
        },
        "Found in /usr/share/perl/5.34/pod/perlfaq7.pod": {
            "content": "Why doesn't \"my($foo) = <$fh>;\" work right?\n\"my()\" and \"local()\" give list context to the right hand side of \"=\".\nThe <$fh> read operation, like so many of Perl's functions and\noperators, can tell which context it was called in and behaves\nappropriately. In general, the scalar() function can help. This function\ndoes nothing to the data itself (contrary to popular myth) but rather\ntells its argument to behave in whatever its scalar fashion is. If that\nfunction doesn't have a defined scalar behavior, this of course doesn't\nhelp you (such as with sort()).\n\nTo enforce scalar context in this particular case, however, you need\nmerely omit the parentheses:\n\nlocal($foo) = <$fh>;        # WRONG\nlocal($foo) = scalar(<$fh>);   # ok\nlocal $foo  = <$fh>;        # right\n\nYou should probably be using lexical variables anyway, although the\nissue is the same here:\n\nmy($foo) = <$fh>;    # WRONG\nmy $foo  = <$fh>;    # right\n\nWhat's the difference between calling a function as &foo and foo()?\n(contributed by brian d foy)\n\nCalling a subroutine as &foo with no trailing parentheses ignores the\nprototype of \"foo\" and passes it the current value of the argument list,\n@. Here's an example; the \"bar\" subroutine calls &foo, which prints its\narguments list:\n\nsub foo { print \"Args in foo are: @\\n\"; }\n\nsub bar { &foo; }\n\nbar( \"a\", \"b\", \"c\" );\n\nWhen you call \"bar\" with arguments, you see that \"foo\" got the same @:\n\nArgs in foo are: a b c\n\nCalling the subroutine with trailing parentheses, with or without\narguments, does not use the current @. Changing the example to put\nparentheses after the call to \"foo\" changes the program:\n\nsub foo { print \"Args in foo are: @\\n\"; }\n\nsub bar { &foo(); }\n\nbar( \"a\", \"b\", \"c\" );\n\nNow the output shows that \"foo\" doesn't get the @ from its caller.\n\nArgs in foo are:\n\nHowever, using \"&\" in the call still overrides the prototype of \"foo\" if\npresent:\n\nsub foo ($$$) { print \"Args infoo are: @\\n\"; }\n\nsub bar1 { &foo; }\nsub bar2 { &foo(); }\nsub bar3 { foo( $[0], $[1], $[2] ); }\n# sub bar4 { foo(); }\n# bar4 doesn't compile: \"Not enough arguments for main::foo at ...\"\n\nbar1( \"a\", \"b\", \"c\" );\n# Args in foo are: a b c\n\nbar2( \"a\", \"b\", \"c\" );\n# Args in foo are:\n\nbar3( \"a\", \"b\", \"c\" );\n# Args in foo are: a b c\n\nThe main use of the @ pass-through feature is to write subroutines\nwhose main job it is to call other subroutines for you. For further\ndetails, see perlsub.\n",
            "subsections": []
        }
    },
    "flags": [],
    "examples": [],
    "see_also": []
}