{
    "mode": "perldoc",
    "parameter": "Shell",
    "section": "-q",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Shell/json",
    "generated": "2026-06-16T06:17:10Z",
    "sections": {
        "Found in /usr/share/perl/5.34/pod/perlfaq8.pod": {
            "content": "How can I call backticks without shell processing?\nThis is a bit tricky. You can't simply write the command like this:\n\n@ok = `grep @opts '$searchstring' @filenames`;\n\nAs of Perl 5.8.0, you can use \"open()\" with multiple arguments. Just\nlike the list forms of \"system()\" and \"exec()\", no shell escapes happen.\n\nopen( GREP, \"-|\", 'grep', @opts, $searchstring, @filenames );\nchomp(@ok = <GREP>);\nclose GREP;\n\nYou can also:\n\nmy @ok = ();\nif (open(GREP, \"-|\")) {\nwhile (<GREP>) {\nchomp;\npush(@ok, $);\n}\nclose GREP;\n} else {\nexec 'grep', @opts, $searchstring, @filenames;\n}\n\nJust as with \"system()\", no shell escapes happen when you \"exec()\" a\nlist. Further examples of this can be found in \"Safe Pipe Opens\" in\nperlipc.\n\nNote that if you're using Windows, no solution to this vexing issue is\neven possible. Even though Perl emulates \"fork()\", you'll still be\nstuck, because Windows does not have an argc/argv-style API.\n\nHow can I convert my shell script to perl?\nLearn Perl and rewrite it. Seriously, there's no simple converter.\nThings that are awkward to do in the shell are easy to do in Perl, and\nthis very awkwardness is what would make a shell->perl converter nigh-on\nimpossible to write. By rewriting it, you'll think about what you're\nreally trying to do, and hopefully will escape the shell's pipeline\ndatastream paradigm, which while convenient for some matters, causes\nmany inefficiencies.\n\nHow do I tell the difference between errors from the shell and perl?\n(answer contributed by brian d foy)\n\nWhen you run a Perl script, something else is running the script for\nyou, and that something else may output error messages. The script might\nemit its own warnings and error messages. Most of the time you cannot\ntell who said what.\n\nYou probably cannot fix the thing that runs perl, but you can change how\nperl outputs its warnings by defining a custom warning and die\nfunctions.\n\nConsider this script, which has an error you may not notice immediately.\n\n#!/usr/locl/bin/perl\n\nprint \"Hello World\\n\";\n\nI get an error when I run this from my shell (which happens to be bash).\nThat may look like perl forgot it has a \"print()\" function, but my\nshebang line is not the path to perl, so the shell runs the script, and\nI get the error.\n\n$ ./test\n./test: line 3: print: command not found\n\nA quick and dirty fix involves a little bit of code, but this may be all\nyou need to figure out the problem.\n\n#!/usr/bin/perl -w\n\nBEGIN {\n$SIG{WARN} = sub{ print STDERR \"Perl: \", @; };\n$SIG{DIE}  = sub{ print STDERR \"Perl: \", @; exit 1};\n}\n\n$a = 1 + undef;\n$x / 0;\nEND\n\nThe perl message comes out with \"Perl\" in front. The \"BEGIN\" block works\nat compile time so all of the compilation errors and warnings get the\n\"Perl:\" prefix too.\n\nPerl: Useless use of division (/) in void context at ./test line 9.\nPerl: Name \"main::a\" used only once: possible typo at ./test line 8.\nPerl: Name \"main::x\" used only once: possible typo at ./test line 9.\nPerl: Use of uninitialized value in addition (+) at ./test line 8.\nPerl: Use of uninitialized value in division (/) at ./test line 9.\nPerl: Illegal division by zero at ./test line 9.\nPerl: Illegal division by zero at -e line 3.\n\nIf I don't see that \"Perl:\", it's not from perl.\n\nYou could also just know all the perl errors, and although there are\nsome people who may know all of them, you probably don't. However, they\nall should be in the perldiag manpage. If you don't find the error in\nthere, it probably isn't a perl error.\n\nLooking up every message is not the easiest way, so let perl to do it\nfor you. Use the diagnostics pragma with turns perl's normal messages\ninto longer discussions on the topic.\n\nuse diagnostics;\n\nIf you don't get a paragraph or two of expanded discussion, it might not\nbe perl's message.\n",
            "subsections": []
        }
    },
    "flags": [],
    "examples": [],
    "see_also": []
}