{
    "mode": "man",
    "parameter": "PERLFAQ3",
    "section": "1",
    "url": "https://www.chedong.com/phpMan.php/man/PERLFAQ3/1/json",
    "generated": "2026-11-27T23:18:46Z",
    "sections": {
        "NAME": {
            "content": "perlfaq3 - Programming Tools\n",
            "subsections": []
        },
        "VERSION": {
            "content": "version 5.20210520\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This section of the FAQ answers questions related to programmer tools and programming\nsupport.\n",
            "subsections": [
                {
                    "name": "How do I do (anything)?",
                    "content": "Have you looked at CPAN (see perlfaq2)? The chances are that someone has already written a\nmodule that can solve your problem.  Have you read the appropriate manpages? Here's a brief\nindex:\n\nBasics\nperldata - Perl data types\nperlvar - Perl pre-defined variables\nperlsyn - Perl syntax\nperlop - Perl operators and precedence\nperlsub - Perl subroutines\nExecution\nperlrun - how to execute the Perl interpreter\nperldebug - Perl debugging\nFunctions\nperlfunc - Perl builtin functions\nObjects\nperlref - Perl references and nested data structures\nperlmod - Perl modules (packages and symbol tables)\nperlobj - Perl objects\nperltie - how to hide an object class in a simple variable\nData Structures\nperlref - Perl references and nested data structures\nperllol - Manipulating arrays of arrays in Perl\nperldsc - Perl Data Structures Cookbook\nModules\nperlmod - Perl modules (packages and symbol tables)\nperlmodlib - constructing new Perl modules and finding existing ones\nRegexes\nperlre - Perl regular expressions\nperlfunc - Perl builtin functions>\nperlop - Perl operators and precedence\nperllocale - Perl locale handling (internationalization and localization)\nMoving to perl5\nperltrap - Perl traps for the unwary\nperl\nLinking with C\nperlxstut - Tutorial for writing XSUBs\nperlxs - XS language reference manual\nperlcall - Perl calling conventions from C\nperlguts - Introduction to the Perl API\nperlembed - how to embed perl in your C program\nVarious\n<http://www.cpan.org/misc/olddoc/FMTEYEWTK.tgz>  (not  a  man-page  but  still  useful, a\ncollection of various essays on Perl techniques)\n\nA crude table of contents for the Perl manpage set is found in perltoc.\n"
                },
                {
                    "name": "How can I use Perl interactively?",
                    "content": "The typical approach uses the Perl debugger, described in the  perldebug(1)  manpage,  on  an\n\"empty\" program, like this:\n\nperl -de 42\n\nNow  just  type  in  any  legal Perl code, and it will be immediately evaluated. You can also\nexamine the symbol table, get stack backtraces, check variable values, set  breakpoints,  and\nother operations typically found in symbolic debuggers.\n\nYou can also use Devel::REPL which is an interactive shell for Perl, commonly known as a REPL\n- Read, Evaluate, Print, Loop. It provides various handy features.\n"
                },
                {
                    "name": "How do I find which modules are installed on my system?",
                    "content": "From the command line, you can use the \"cpan\" command's \"-l\" switch:\n\n$ cpan -l\n\nYou can also use \"cpan\"'s \"-a\" switch to create an autobundle file that \"CPAN.pm\" understands\nand can use to re-install every module:\n\n$ cpan -a\n\nInside  a  Perl  program,  you  can  use the ExtUtils::Installed module to show all installed\ndistributions, although it can take awhile to do its magic. The standard library which  comes\nwith Perl just shows up as \"Perl\" (although you can get those with Module::CoreList).\n\nuse ExtUtils::Installed;\n\nmy $inst    = ExtUtils::Installed->new();\nmy @modules = $inst->modules();\n\nIf you want a list of all of the Perl module filenames, you can use File::Find::Rule:\n\nuse File::Find::Rule;\n\nmy @files = File::Find::Rule->\nextras({follow => 1})->\nfile()->\nname( '*.pm' )->\nin( @INC )\n;\n\nIf  you  do  not have that module, you can do the same thing with File::Find which is part of\nthe standard library:\n\nuse File::Find;\nmy @files;\n\nfind(\n{\nwanted => sub {\npush @files, $File::Find::fullname\nif -f $File::Find::fullname && /\\.pm$/\n},\nfollow => 1,\nfollowskip => 2,\n},\n@INC\n);\n\nprint join \"\\n\", @files;\n\nIf you simply need to check quickly to see if a module is available, you can  check  for  its\ndocumentation. If you can read the documentation the module is most likely installed.  If you\ncannot read the documentation, the module might not have any (in rare cases):\n\n$ perldoc Module::Name\n\nYou can also try to include the module in a one-liner to see if perl finds it:\n\n$ perl -MModule::Name -e1\n\n(If  you don't receive a \"Can't locate ... in @INC\" error message, then Perl found the module\nname you asked for.)\n"
                },
                {
                    "name": "How do I debug my Perl programs?",
                    "content": "(contributed by brian d foy)\n\nBefore you do anything else, you can help yourself by ensuring that you  let  Perl  tell  you\nabout  problem  areas  in  your code. By turning on warnings and strictures, you can head off\nmany problems before they get too big. You can find  out  more  about  these  in  strict  and\nwarnings.\n\n#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nBeyond  that,  the simplest debugger is the \"print\" function. Use it to look at values as you\nrun your program:\n\nprint STDERR \"The value is [$value]\\n\";\n\nThe Data::Dumper module can pretty-print Perl data structures:\n\nuse Data::Dumper qw( Dumper );\nprint STDERR \"The hash is \" . Dumper( \\%hash ) . \"\\n\";\n\nPerl comes with an interactive debugger, which you can start with the \"-d\" switch. It's fully\nexplained in perldebug.\n\nIf you'd like a graphical user interface and you have Tk, you can use \"ptkdb\". It's  on  CPAN\nand available for free.\n\nIf  you  need  something much more sophisticated and controllable, Leon Brocard's Devel::ebug\n(which you can call with the \"-D\" switch as \"-Debug\") gives you the programmatic  hooks  into\neverything you need to write your own (without too much pain and suffering).\n\nYou  can  also  use  a commercial debugger such as Affrus (Mac OS X), Komodo from Activestate\n(Windows and Mac OS X), or EPIC (most platforms).\n"
                },
                {
                    "name": "How do I profile my Perl programs?",
                    "content": "(contributed by brian d foy, updated Fri Jul 25 12:22:26 PDT 2008)\n\nThe \"Devel\" namespace has several modules which you can use to profile your Perl programs.\n\nThe Devel::NYTProf (New York Times Profiler) does both statement  and  subroutine  profiling.\nIt's available from CPAN and you also invoke it with the \"-d\" switch:\n\nperl -d:NYTProf someperl.pl\n\nIt  creates  a  database  of  the  profile  information  that  you can turn into reports. The\n\"nytprofhtml\" command turns the data into an HTML report similar to the Devel::Cover report:\n\nnytprofhtml\n\nYou might also be interested in using the Benchmark to measure and compare code snippets.\n\nYou can read more about profiling in Programming Perl, chapter 20, or Mastering Perl, chapter\n5.\n\nperldebguts documents creating a custom debugger if you need to  create  a  special  sort  of\nprofiler.  brian d foy describes the process in The Perl Journal, \"Creating a Perl Debugger\",\n<http://www.ddj.com/184404522> , and \"Profiling in Perl\" <http://www.ddj.com/184404580> .\n\nPerl.com has two interesting articles  on  profiling:  \"Profiling  Perl\",  by  Simon  Cozens,\n<https://www.perl.com/pub/2004/06/25/profiling.html/>  and  \"Debugging and Profiling modperl\nApplications\", by Frank Wiles, <http://www.perl.com/pub/a/2006/02/09/debugmodperl.html> .\n\nRandal L. Schwartz writes about profiling in  \"Speeding  up  Your  Perl  Programs\"  for  Unix\nReview, <http://www.stonehenge.com/merlyn/UnixReview/col49.html> , and \"Profiling in Template\nToolkit           via           Overriding\"           for           Linux           Magazine,\n<http://www.stonehenge.com/merlyn/LinuxMag/col75.html> .\n"
                },
                {
                    "name": "How do I cross-reference my Perl programs?",
                    "content": "The B::Xref module can be used to generate cross-reference reports for Perl programs.\n\nperl -MO=Xref[,OPTIONS] scriptname.plx\n"
                },
                {
                    "name": "Is there a pretty-printer (formatter) for Perl?",
                    "content": "Perl::Tidy comes with a perl script perltidy which indents and reformats Perl scripts to make\nthem easier to read by trying to follow the rules of the perlstyle. If  you  write  Perl,  or\nspend much time reading Perl, you will probably find it useful.\n\nOf  course, if you simply follow the guidelines in perlstyle, you shouldn't need to reformat.\nThe habit of formatting your code as you write it will help prevent bugs. Your editor can and\nshould help you with this. The perl-mode or newer cperl-mode for emacs can provide remarkable\namounts of help with most (but not all) code, and even less programmable editors can  provide\nsignificant  assistance.  Tom  Christiansen  and  many  other VI users swear by the following\nsettings in vi and its clones:\n\nset ai sw=4\nmap! ^O {^M}^[O^T\n\nPut that in your .exrc file (replacing the caret characters with control characters) and away\nyou go. In  insert  mode,  ^T  is  for  indenting,  ^D  is  for  undenting,  and  ^O  is  for\nblockdenting--as  it  were.  A  more  complete  example,  with  comments,  can  be  found  at\n<http://www.cpan.org/authors/id/T/TO/TOMC/scripts/toms.exrc.gz>\n"
                },
                {
                    "name": "Is there an IDE or Windows Perl Editor?",
                    "content": "Perl programs are just plain text, so any editor will do.\n\nIf you're on Unix, you  already  have  an  IDE--Unix  itself.  The  Unix  philosophy  is  the\nphilosophy  of  several  small  tools  that  each  do  one  thing and do it well. It's like a\ncarpenter's toolbox.\n\nIf you want an IDE, check the following (in alphabetical order, not order of preference):\n\nEclipse\n<http://e-p-i-c.sf.net/>\n\nThe Eclipse Perl Integration Project integrates Perl editing/debugging with Eclipse.\n\nEnginsite\n<http://www.enginsite.com/>\n\nPerl Editor by EngInSite is a  complete  integrated  development  environment  (IDE)  for\ncreating,  testing,  and  debugging  Perl scripts; the tool runs on Windows 9x/NT/2000/XP\nor later.\n\nIntelliJ IDEA\n<https://plugins.jetbrains.com/plugin/7796>\n\nCamelcade plugin provides Perl5 support in IntelliJ IDEA and other JetBrains IDEs.\n\nKephra\n<http://kephra.sf.net>\n\nGUI editor written in Perl using wxWidgets and Scintilla with lots of  smaller  features.\nAims  for  a  UI based on Perl principles like TIMTOWTDI and \"easy things should be easy,\nhard things should be possible\".\n\nKomodo\n<http://www.ActiveState.com/Products/Komodo/>\n\nActiveState's cross-platform (as of October 2004, that's Windows,  Linux,  and  Solaris),\nmulti-language  IDE  has Perl support, including a regular expression debugger and remote\ndebugging.\n\nNotepad++\n<http://notepad-plus.sourceforge.net/>\n\nOpen Perl IDE\n<http://open-perl-ide.sourceforge.net/>\n\nOpen Perl IDE is an integrated development environment for  writing  and  debugging  Perl\nscripts with ActiveState's ActivePerl distribution under Windows 95/98/NT/2000.\n\nOptiPerl\n<http://www.optiperl.com/>\n\nOptiPerl  is a Windows IDE with simulated CGI environment, including debugger and syntax-\nhighlighting editor.\n\nPadre\n<http://padre.perlide.org/>\n\nPadre is cross-platform IDE for Perl written in Perl using wxWidgets to provide a  native\nlook  and  feel. It's open source under the Artistic License. It is one of the newer Perl\nIDEs.\n\nPerlBuilder\n<http://www.solutionsoft.com/perl.htm>\n\nPerlBuilder is an integrated development  environment  for  Windows  that  supports  Perl\ndevelopment.\n\nvisiPerl+\n<http://helpconsulting.net/visiperl/index.html>\n\nFrom Help Consulting, for Windows.\n\nVisual Perl\n<http://www.activestate.com/Products/VisualPerl/>\n\nVisual Perl is a Visual Studio.NET plug-in from ActiveState.\n\nZeus\n<http://www.zeusedit.com/lookmain.html>\n\nZeus  for  Windows is another Win32 multi-language editor/IDE that comes with support for\nPerl.\n\nFor editors: if you're on Unix you probably have vi or a vi clone already,  and  possibly  an\nemacs  too, so you may not need to download anything. In any emacs the cperl-mode (M-x cperl-\nmode) gives you perhaps the best available Perl editing mode in any editor.\n\nIf you are using Windows, you can use any editor that lets you work with plain text, such  as\nNotePad  or WordPad. Word processors, such as Microsoft Word or WordPerfect, typically do not\nwork since they insert all sorts of behind-the-scenes information, although some allow you to\nsave files as \"Text Only\". You can also  download  text  editors  designed  specifically  for\nprogramming,    such   as   Textpad   (   <http://www.textpad.com/>   )   and   UltraEdit   (\n<http://www.ultraedit.com/> ), among others.\n\nIf you are using MacOS, the same concerns apply. MacPerl  (for  Classic  environments)  comes\nwith     a     simple     editor.     Popular     external     editors     are    BBEdit    (\n<http://www.barebones.com/products/bbedit/>          )          or          Alpha           (\n<http://www.his.com/~jguyer/Alpha/Alpha8.html> ). MacOS X users can use Unix editors as well.\n\nGNU Emacs\n<http://www.gnu.org/software/emacs/windows/ntemacs.html>\n\nMicroEMACS\n<http://www.microemacs.de/>\n\nXEmacs\n<http://www.xemacs.org/Download/index.html>\n\nJed <http://space.mit.edu/~davis/jed/>\n\nor a vi clone such as\n\nVim <http://www.vim.org/>\n\nVile\n<http://invisible-island.net/vile/vile.html>\n\nThe following are Win32 multilanguage editor/IDEs that support Perl:\n\nMultiEdit\n<http://www.MultiEdit.com/>\n\nSlickEdit\n<http://www.slickedit.com/>\n\nConTEXT\n<http://www.contexteditor.org/>\n\nThere is also a toyedit Text widget based editor written in Perl that is distributed with the\nTk  module on CPAN. The ptkdb ( <http://ptkdb.sourceforge.net/> ) is a Perl/Tk-based debugger\nthat   acts    as    a    development    environment    of    sorts.    Perl    Composer    (\n<http://perlcomposer.sourceforge.net/> ) is an IDE for Perl/Tk GUI creation.\n\nIn addition to an editor/IDE you might be interested in a more powerful shell environment for\nWin32. Your options include\n\nbash\nfrom the Cygwin package ( <http://cygwin.com/> )\n\nzsh <http://www.zsh.org/>\n\nCygwin is covered by the GNU General Public License (but that shouldn't matter for Perl use).\nCygwin  contains  (in  addition  to  the  shell) a comprehensive set of standard Unix toolkit\nutilities.\n\nBBEdit and TextWrangler\nare text editors for OS X that have a Perl sensitivity mode ( <http://www.barebones.com/>\n).\n"
                },
                {
                    "name": "Where can I get Perl macros for vi?",
                    "content": "For   a   complete   version   of   Tom   Christiansen's   vi   configuration    file,    see\n<http://www.cpan.org/authors/id/T/TO/TOMC/scripts/toms.exrc.gz> , the standard benchmark file\nfor  vi  emulators.  The  file runs best with nvi, the current version of vi out of Berkeley,\nwhich   incidentally   can   be   built    with    an    embedded    Perl    interpreter--see\n<http://www.cpan.org/src/misc/> .\n"
                },
                {
                    "name": "Where can I get perl-mode or cperl-mode for emacs?",
                    "content": "Since  Emacs  version 19 patchlevel 22 or so, there have been both a perl-mode.el and support\nfor the Perl debugger built in. These should come with the standard Emacs 19 distribution.\n\nNote that the perl-mode of emacs will have fits with \"main'foo\" (single quote), and  mess  up\nthe indentation and highlighting. You are probably using \"main::foo\" in new Perl code anyway,\nso this shouldn't be an issue.\n\nFor CPerlMode, see <http://www.emacswiki.org/cgi-bin/wiki/CPerlMode>\n"
                },
                {
                    "name": "How can I use curses with Perl?",
                    "content": "The  Curses  module  from  CPAN  provides a dynamically loadable object module interface to a\ncurses    library.    A    small    demo    can     be     found     at     the     directory\n<http://www.cpan.org/authors/id/T/TO/TOMC/scripts/rep.gz>  ;  this  program repeats a command\nand updates the screen as needed, rendering rep ps axu similar to top.\n"
                },
                {
                    "name": "How can I write a GUI (X, Tk, Gtk, etc.) in Perl?",
                    "content": "(contributed by Ben Morrow)\n\nThere are a number of modules which let you write GUIs in Perl. Most GUI toolkits have a perl\ninterface: an incomplete list follows.\n\nTk  This works under Unix and Windows, and the current version doesn't look half as bad under\nWindows as it used to. Some of the gui elements still don't 'feel' quite  right,  though.\nThe  interface is very natural and 'perlish', making it easy to use in small scripts that\njust need a simple gui. It hasn't been updated in a while.\n\nWx  This   is   a   Perl   binding   for   the    cross-platform    wxWidgets    toolkit    (\n<http://www.wxwidgets.org>  ).  It  works  under  Unix,  Win32 and Mac OS X, using native\nwidgets (Gtk under Unix). The interface  follows  the  C++  interface  closely,  but  the\ndocumentation  is  a  little sparse for someone who doesn't know the library, mostly just\nreferring you to the C++ documentation.\n\nGtk and Gtk2\nThese are Perl bindings for the Gtk  toolkit  (  <http://www.gtk.org>  ).  The  interface\nchanged  significantly  between  versions  1 and 2 so they have separate Perl modules. It\nruns under Unix, Win32 and Mac OS X (currently it requires an X server on Mac OS,  but  a\n'native'  port  is underway), and the widgets look the same on every platform: i.e., they\ndon't match the native widgets. As with Wx, the Perl bindings follow the C  API  closely,\nand the documentation requires you to read the C documentation to understand it.\n\nWin32::GUI\nThis provides access to most of the Win32 GUI widgets from Perl.  Obviously, it only runs\nunder  Win32,  and  uses  native  widgets. The Perl interface doesn't really follow the C\ninterface: it's been made more Perlish,  and  the  documentation  is  pretty  good.  More\nadvanced stuff may require familiarity with the C Win32 APIs, or reference to MSDN.\n\nCamelBones\nCamelBones  (  <http://camelbones.sourceforge.net>  )  is  a Perl interface to Mac OS X's\nCocoa GUI toolkit, and as such can be used to produce native GUIs on Mac OS X.  It's  not\non  CPAN,  as  it  requires  frameworks  that  CPAN.pm  doesn't  know how to install, but\ninstallation is via the standard OSX package installer. The  Perl  API  is,  again,  very\nclose  to  the  ObjC  API  it's  wrapping,  and  the  documentation just tells you how to\ntranslate from one to the other.\n\nQt  There is a Perl interface to TrollTech's Qt  toolkit,  but  it  does  not  appear  to  be\nmaintained.\n\nAthena\nSx  is an interface to the Athena widget set which comes with X, but again it appears not\nto be much used nowadays.\n"
                },
                {
                    "name": "How can I make my Perl program run faster?",
                    "content": "The best way to do this is to come up with a better algorithm. This can often make a dramatic\ndifference. Jon Bentley's book Programming Pearls (that's not a misspelling!)  has some  good\ntips  on  optimization,  too.  Advice on benchmarking boils down to: benchmark and profile to\nmake sure you're optimizing the right part, look for better algorithms instead of microtuning\nyour code, and when all else fails consider just buying faster hardware.  You  will  probably\nwant  to  read the answer to the earlier question \"How do I profile my Perl programs?\" if you\nhaven't done so already.\n\nA different approach is to autoload seldom-used Perl code. See the AutoSplit  and  AutoLoader\nmodules  in  the standard distribution for that. Or you could locate the bottleneck and think\nabout writing just that part in C, the way we used to take bottlenecks in C  code  and  write\nthem  in  assembler.  Similar  to  rewriting in C, modules that have critical sections can be\nwritten in C (for instance, the PDL module from CPAN).\n\nIf you're currently linking your perl executable to a shared libc.so, you can  often  gain  a\n10-25%  performance  benefit by rebuilding it to link with a static libc.a instead. This will\nmake a bigger perl executable, but your Perl programs (and programmers) may thank you for it.\nSee the INSTALL file in the source distribution for more information.\n\nThe undump program was an ancient attempt to speed up Perl program by  storing  the  already-\ncompiled  form  to  disk.  This  is  no  longer  a  viable option, as it only worked on a few\narchitectures, and wasn't a good solution anyway.\n"
                },
                {
                    "name": "How can I make my Perl program take less memory?",
                    "content": "When it comes to time-space tradeoffs, Perl nearly  always  prefers  to  throw  memory  at  a\nproblem.  Scalars  in Perl use more memory than strings in C, arrays take more than that, and\nhashes use even more. While there's still a  lot  to  be  done,  recent  releases  have  been\naddressing these issues. For example, as of 5.004, duplicate hash keys are shared amongst all\nhashes using them, so require no reallocation.\n\nIn  some  cases,  using  substr()  or  vec() to simulate arrays can be highly beneficial. For\nexample, an array of a thousand booleans will take at least 20,000 bytes of space, but it can\nbe turned  into  one  125-byte  bit  vector--a  considerable  memory  savings.  The  standard\nTie::SubstrHash  module  can also help for certain types of data structure. If you're working\nwith specialist data structures (matrices, for instance) modules that implement  these  in  C\nmay use less memory than equivalent Perl modules.\n\nAnother  thing  to  try  is learning whether your Perl was compiled with the system malloc or\nwith Perl's builtin malloc. Whichever one it is, try using the other one and see whether this\nmakes a difference.   Information  about  malloc  is  in  the  INSTALL  file  in  the  source\ndistribution.  You  can  find  out  whether  you  are  using  perl's  malloc  by typing \"perl\n-V:usemymalloc\".\n\nOf course, the best way to save memory is to not do anything to waste it in the first  place.\nGood programming practices can go a long way toward this:\n\nDon't slurp!\nDon't  read  an  entire  file  into  memory  if  you can process it line by line. Or more\nconcretely, use a loop like this:\n\n#\n# Good Idea\n#\nwhile (my $line = <$filehandle>) {\n# ...\n}\n\ninstead of this:\n\n#\n# Bad Idea\n#\nmy @data = <$filehandle>;\nforeach (@data) {\n# ...\n}\n\nWhen the files you're processing are small, it doesn't much matter which way you  do  it,\nbut it makes a huge difference when they start getting larger.\n\nUse map and grep selectively\nRemember that both map and grep expect a LIST argument, so doing this:\n\n@wanted = grep {/pattern/} <$filehandle>;\n\nwill cause the entire file to be slurped. For large files, it's better to loop:\n\nwhile (<$filehandle>) {\npush(@wanted, $) if /pattern/;\n}\n\nAvoid unnecessary quotes and stringification\nDon't quote large strings unless absolutely necessary:\n\nmy $copy = \"$largestring\";\n\nmakes 2 copies of $largestring (one for $copy and another for the quotes), whereas\n\nmy $copy = $largestring;\n\nonly makes one copy.\n\nDitto for stringifying large arrays:\n\n{\nlocal $, = \"\\n\";\nprint @bigarray;\n}\n\nis much more memory-efficient than either\n\nprint join \"\\n\", @bigarray;\n\nor\n\n{\nlocal $\" = \"\\n\";\nprint \"@bigarray\";\n}\n\nPass by reference\nPass  arrays  and  hashes by reference, not by value. For one thing, it's the only way to\npass multiple lists or hashes (or both) in a single call/return. It also avoids  creating\na  copy  of  all the contents. This requires some judgement, however, because any changes\nwill be propagated back to the original data. If you really want to mangle (er, modify) a\ncopy, you'll have to sacrifice the memory needed to make one.\n\nTie large variables to disk\nFor \"big\" data stores (i.e. ones that exceed available memory) consider using one of  the\nDB  modules  to  store  it on disk instead of in RAM. This will incur a penalty in access\ntime, but that's probably better than causing your hard disk to  thrash  due  to  massive\nswapping.\n"
                },
                {
                    "name": "Is it safe to return a reference to local or lexical data?",
                    "content": "Yes. Perl's garbage collection system takes care of this so everything works out right.\n\nsub makeone {\nmy @a = ( 1 .. 10 );\nreturn \\@a;\n}\n\nfor ( 1 .. 10 ) {\npush @many, makeone();\n}\n\nprint $many[4][5], \"\\n\";\n\nprint \"@many\\n\";\n"
                },
                {
                    "name": "How can I free an array or hash so my program shrinks?",
                    "content": "(contributed by Michael Carman)\n\nYou  usually can't. Memory allocated to lexicals (i.e. my() variables) cannot be reclaimed or\nreused even if they go out of scope. It is reserved in case  the  variables  come  back  into\nscope.  Memory  allocated  to  global  variables can be reused (within your program) by using\nundef() and/or delete().\n\nOn most operating systems, memory allocated to a program can never be returned to the system.\nThat's why long-running programs  sometimes  re-  exec  themselves.  Some  operating  systems\n(notably,  systems that use mmap(2) for allocating large chunks of memory) can reclaim memory\nthat is no longer used, but on such systems, perl must be configured and compiled to use  the\nOS's malloc, not perl's.\n\nIn general, memory allocation and de-allocation isn't something you can or should be worrying\nabout much in Perl.\n\nSee also \"How can I make my Perl program take less memory?\"\n"
                },
                {
                    "name": "How can I make my CGI script more efficient?",
                    "content": "Beyond  the  normal measures described to make general Perl programs faster or smaller, a CGI\nprogram has additional issues. It may be run several times per second. Given that  each  time\nit  runs  it will need to be re-compiled and will often allocate a megabyte or more of system\nmemory, this can be a killer. Compiling into C isn't going to help you  because  the  process\nstart-up overhead is where the bottleneck is.\n\nThere are three popular ways to avoid this overhead. One solution involves running the Apache\nHTTP  server  (available  from  <http://www.apache.org/>  )  with  either  of the modperl or\nmodfastcgi plugin modules.\n\nWith modperl and the Apache::Registry module (distributed with  modperl),  httpd  will  run\nwith  an embedded Perl interpreter which pre-compiles your script and then executes it within\nthe same address space without forking. The Apache extension also gives Perl  access  to  the\ninternal  server  API, so modules written in Perl can do just about anything a module written\nin C can. For more on modperl, see <http://perl.apache.org/>\n\nWith  the  FCGI  module  (from   CPAN)   and   the   modfastcgi   module   (available   from\n<http://www.fastcgi.com/>  )  each  of  your  Perl  programs  becomes  a permanent CGI daemon\nprocess.\n\nFinally, Plack is a Perl module and  toolkit  that  contains  PSGI  middleware,  helpers  and\nadapters  to  web  servers, allowing you to easily deploy scripts which can continue running,\nand provides flexibility with regards to which web server you use. It can allow existing  CGI\nscripts  to enjoy this flexibility and performance with minimal changes, or can be used along\nwith modern Perl web frameworks to make writing  and  deploying  web  services  with  Perl  a\nbreeze.\n\nThese  solutions  can  have far-reaching effects on your system and on the way you write your\nCGI programs, so investigate them with care.\n\nSee also <http://www.cpan.org/modules/by-category/15WorldWideWebHTMLHTTPCGI/> .\n"
                },
                {
                    "name": "How can I hide the source for my Perl program?",
                    "content": "Delete it. :-) Seriously, there are  a  number  of  (mostly  unsatisfactory)  solutions  with\nvarying levels of \"security\".\n\nFirst of all, however, you can't take away read permission, because the source code has to be\nreadable  in  order  to  be  compiled and interpreted. (That doesn't mean that a CGI script's\nsource is readable by  people  on  the  web,  though--only  by  people  with  access  to  the\nfilesystem.)  So you have to leave the permissions at the socially friendly 0755 level.\n\nSome  people  regard  this  as  a  security problem. If your program does insecure things and\nrelies on people not knowing how to exploit those insecurities, it is not secure. It is often\npossible for someone to determine the insecure things and exploit them  without  viewing  the\nsource.  Security through obscurity, the name for hiding your bugs instead of fixing them, is\nlittle security indeed.\n\nYou can try using encryption via source filters (Starting from Perl  5.8  the  Filter::Simple\nand  Filter::Util::Call  modules  are  included in the standard distribution), but any decent\nprogrammer will be able to decrypt  it.  You  can  try  using  the  byte  code  compiler  and\ninterpreter  described  later  in perlfaq3, but the curious might still be able to de-compile\nit. You can try using the native-code compiler described later, but crackers might be able to\ndisassemble it. These pose varying degrees of difficulty to people wanting  to  get  at  your\ncode, but none can definitively conceal it (true of every language, not just Perl).\n\nIt  is  very  easy to recover the source of Perl programs. You simply feed the program to the\nperl interpreter and use the modules in the B:: hierarchy. The B::Deparse  module  should  be\nable to defeat most attempts to hide source. Again, this is not unique to Perl.\n\nIf  you're  concerned  about  people  profiting  from your code, then the bottom line is that\nnothing but a restrictive license will give you legal security.  License  your  software  and\npepper  it  with threatening statements like \"This is unpublished proprietary software of XYZ\nCorp.  Your access to it does not give you permission to use it blah blah blah.\"  We are  not\nlawyers,  of course, so you should see a lawyer if you want to be sure your license's wording\nwill stand up in court.\n"
                },
                {
                    "name": "How can I compile my Perl program into byte code or C?",
                    "content": "(contributed by brian d foy)\n\nIn general, you can't do this. There are some things that may work for your situation though.\nPeople usually ask this question because they want to distribute their works  without  giving\naway  the  source  code,  and  most solutions trade disk space for convenience.  You probably\nwon't see much of a speed  increase  either,  since  most  solutions  simply  bundle  a  Perl\ninterpreter in the final product (but see \"How can I make my Perl program run faster?\").\n\nThe  Perl Archive Toolkit is Perl's analog to Java's JAR. It's freely available and on CPAN (\n<https://metacpan.org/pod/PAR> ).\n\nThere are also some commercial products that may work for you, although you  have  to  buy  a\nlicense for them.\n\nThe Perl Dev Kit ( <http://www.activestate.com/Products/PerlDevKit/> ) from ActiveState can\n\"Turn  your  Perl  programs  into  ready-to-run  executables  for  HP-UX,  Linux, Solaris and\nWindows.\"\n\nPerl2Exe  (  <http://www.indigostar.com/perl2exe.htm>  )  is  a  command  line  program   for\nconverting perl scripts to executable files. It targets both Windows and Unix platforms.\n"
                },
                {
                    "name": "How can I get \"#!perl\" to work on [MS-DOS,NT,...]?",
                    "content": "For OS/2 just use\n\nextproc perl -S -yourswitches\n\nas  the  first  line in \"*.cmd\" file (\"-S\" due to a bug in cmd.exe's \"extproc\" handling). For\nDOS one should first invent a corresponding batch file and codify it  in  \"ALTERNATESHEBANG\"\n(see the dosish.h file in the source distribution for more information).\n\nThe  Win95/NT installation, when using the ActiveState port of Perl, will modify the Registry\nto associate the \".pl\" extension with the perl interpreter.  If  you  install  another  port,\nperhaps  even  building  your  own Win95/NT Perl from the standard sources by using a Windows\nport of gcc (e.g., with cygwin or mingw32), then you'll have to modify the Registry yourself.\nIn  addition  to  associating  \".pl\"  with  the  interpreter,  NT  people   can   use:   \"SET\nPATHEXT=%PATHEXT%;.PL\"  to  let  them  run  the  program  \"install-linux.pl\" merely by typing\n\"install-linux\".\n\nUnder \"Classic\" MacOS, a perl program will have the appropriate Creator  and  Type,  so  that\ndouble-clicking them will invoke the MacPerl application.  Under Mac OS X, clickable apps can\nbe    made    from    any    \"#!\"    script    using   Wil   Sanchez'   DropScript   utility:\n<http://www.wsanchez.net/software/> .\n\nIMPORTANT!: Whatever you do, PLEASE don't get frustrated, and just throw the perl interpreter\ninto your cgi-bin directory, in order to get your programs working for a web server. This  is\nan EXTREMELY big security risk. Take the time to figure out how to do it correctly.\n"
                },
                {
                    "name": "Can I write useful Perl programs on the command line?",
                    "content": "Yes.  Read  perlrun  for more information. Some examples follow.  (These assume standard Unix\nshell quoting rules.)\n\n# sum first and last fields\nperl -lane 'print $F[0] + $F[-1]' *\n\n# identify text files\nperl -le 'for(@ARGV) {print if -f && -T }' *\n\n# remove (most) comments from C program\nperl -0777 -pe 's{/\\*.*?\\*/}{}gs' foo.c\n\n# make file a month younger than today, defeating reaper daemons\nperl -e '$X=24*60*60; utime(time(),time() + 30 * $X,@ARGV)' *\n\n# find first unused uid\nperl -le '$i++ while getpwuid($i); print $i'\n\n# display reasonable manpath\necho $PATH | perl -nl -072 -e '\ns![^/+]*$!man!&&-d&&!$s{$}++&&push@m,$;END{print\"@m\"}'\n\nOK, the last one was actually an Obfuscated Perl Contest entry. :-)\n"
                },
                {
                    "name": "Why don't Perl one-liners work on my DOS/Mac/VMS system?",
                    "content": "The problem is usually that the command interpreters on those systems have  rather  different\nideas  about  quoting  than  the Unix shells under which the one-liners were created. On some\nsystems, you may have to change single-quotes to double ones, which you must NOT do  on  Unix\nor Plan9 systems. You might also have to change a single % to a %%.\n\nFor example:\n\n# Unix (including Mac OS X)\nperl -e 'print \"Hello world\\n\"'\n\n# DOS, etc.\nperl -e \"print \\\"Hello world\\n\\\"\"\n\n# Mac Classic\nprint \"Hello world\\n\"\n(then Run \"Myscript\" or Shift-Command-R)\n\n# MPW\nperl -e 'print \"Hello world\\n\"'\n\n# VMS\nperl -e \"print \"\"Hello world\\n\"\"\"\n\nThe  problem  is  that  none  of  these  examples  are  reliable:  they depend on the command\ninterpreter. Under Unix, the first two often work. Under DOS,  it's  entirely  possible  that\nneither works. If 4DOS was the command shell, you'd probably have better luck like this:\n\nperl -e \"print <Ctrl-x>\"Hello world\\n<Ctrl-x>\"\"\n\nUnder the Mac, it depends which environment you are using. The MacPerl shell, or MPW, is much\nlike  Unix  shells in its support for several quoting variants, except that it makes free use\nof the Mac's non-ASCII characters as control characters.\n\nUsing qq(), q(), and qx(), instead of \"double quotes\", 'single quotes', and `backticks`,  may\nmake one-liners easier to write.\n\nThere is no general solution to all of this. It is a mess.\n\n[Some of this answer was contributed by Kenneth Albanowski.]\n"
                },
                {
                    "name": "Where can I learn about CGI or Web programming in Perl?",
                    "content": "For  modules,  get  the  CGI  or LWP modules from CPAN. For textbooks, see the two especially\ndedicated to web stuff in the question on books. For problems and questions  related  to  the\nweb,  like  \"Why  do  I get 500 Errors\" or \"Why doesn't it run from the browser right when it\nruns fine on the command line\", see the troubleshooting guides and references in perlfaq9  or\nin the CGI MetaFAQ:\n\nL<http://www.perl.org/CGIMetaFAQ.html>\n\nLooking  into  <https://plackperl.org>  and modern Perl web frameworks is highly recommended,\nthough; web programming in Perl has evolved a long way  from  the  old  days  of  simple  CGI\nscripts.\n"
                },
                {
                    "name": "Where can I learn about object-oriented Perl programming?",
                    "content": "A good place to start is perlootut, and you can use perlobj for reference.\n\nA  good  book  on  OO  on  Perl  is  the \"Object-Oriented Perl\" by Damian Conway from Manning\nPublications, or \"Intermediate Perl\" by Randal Schwartz, brian d foy, and  Tom  Phoenix  from\nO'Reilly Media.\n"
                },
                {
                    "name": "Where can I learn about linking C with Perl?",
                    "content": "If  you  want  to  call  C  from Perl, start with perlxstut, moving on to perlxs, xsubpp, and\nperlguts. If you want to call Perl from C, then read perlembed, perlcall, and perlguts. Don't\nforget that you can learn a lot from looking at how the authors of existing extension modules\nwrote their code and solved their problems.\n\nYou might not need all the power of XS. The Inline::C module lets you put C code directly  in\nyour  Perl source. It handles all the magic to make it work. You still have to learn at least\nsome of the perl API but you won't have to deal with the complexity of the XS support files.\n"
                },
                {
                    "name": "I've read perlembed, perlguts, etc., but I can't embed perl in my C  program;  what  am  I  doing",
                    "content": ""
                },
                {
                    "name": "wrong?",
                    "content": "Download  the  ExtUtils::Embed kit from CPAN and run `make test'. If the tests pass, read the\npods  again   and   again   and   again.   If   they   fail,   submit   a   bug   report   to\n<https://github.com/Perl/perl5/issues>  with  the  output of \"make test TESTVERBOSE=1\" along\nwith \"perl -V\".\n"
                },
                {
                    "name": "When I tried to run my script, I got this message. What does it mean?",
                    "content": "A complete list of Perl's error messages and warnings with explanatory text can be  found  in\nperldiag.  You  can  also use the splain program (distributed with Perl) to explain the error\nmessages:\n\nperl program 2>diag.out\nsplain [-v] [-p] diag.out\n\nor change your program to explain the messages for you:\n\nuse diagnostics;\n\nor\n\nuse diagnostics -verbose;\n"
                },
                {
                    "name": "What's MakeMaker?",
                    "content": "(contributed by brian d foy)\n\nThe ExtUtils::MakeMaker module, better known simply as  \"MakeMaker\",  turns  a  Perl  script,\ntypically  called  \"Makefile.PL\",  into  a  Makefile.  The Unix tool \"make\" uses this file to\nmanage dependencies and actions to process and install a Perl distribution.\n"
                }
            ]
        },
        "AUTHOR AND COPYRIGHT": {
            "content": "Copyright (c) 1997-2010 Tom Christiansen, Nathan Torkington, and other authors as noted.  All\nrights reserved.\n\nThis  documentation is free; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n\nIrrespective of its distribution, all code examples here are in the public  domain.  You  are\npermitted  and  encouraged  to use this code and any derivatives thereof in your own programs\nfor fun or for profit as you see fit. A simple comment in the code giving credit to  the  FAQ\nwould be courteous but is not required.\n\nperl v5.38.2                                 2026-08-18                                  PERLFAQ3(1)",
            "subsections": []
        }
    },
    "summary": "perlfaq3 - Programming Tools",
    "flags": [],
    "examples": [],
    "see_also": []
}