| 1 | .\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13 |
| 2 | .\" |
| 3 | .\" Standard preamble: |
| 4 | .\" ======================================================================== |
| 5 | .de Sh \" Subsection heading |
| 6 | .br |
| 7 | .if t .Sp |
| 8 | .ne 5 |
| 9 | .PP |
| 10 | \fB\\$1\fR |
| 11 | .PP |
| 12 | .. |
| 13 | .de Sp \" Vertical space (when we can't use .PP) |
| 14 | .if t .sp .5v |
| 15 | .if n .sp |
| 16 | .. |
| 17 | .de Vb \" Begin verbatim text |
| 18 | .ft CW |
| 19 | .nf |
| 20 | .ne \\$1 |
| 21 | .. |
| 22 | .de Ve \" End verbatim text |
| 23 | .ft R |
| 24 | .fi |
| 25 | .. |
| 26 | .\" Set up some character translations and predefined strings. \*(-- will |
| 27 | .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left |
| 28 | .\" double quote, and \*(R" will give a right double quote. | will give a |
| 29 | .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to |
| 30 | .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' |
| 31 | .\" expand to `' in nroff, nothing in troff, for use with C<>. |
| 32 | .tr \(*W-|\(bv\*(Tr |
| 33 | .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' |
| 34 | .ie n \{\ |
| 35 | . ds -- \(*W- |
| 36 | . ds PI pi |
| 37 | . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch |
| 38 | . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch |
| 39 | . ds L" "" |
| 40 | . ds R" "" |
| 41 | . ds C` "" |
| 42 | . ds C' "" |
| 43 | 'br\} |
| 44 | .el\{\ |
| 45 | . ds -- \|\(em\| |
| 46 | . ds PI \(*p |
| 47 | . ds L" `` |
| 48 | . ds R" '' |
| 49 | 'br\} |
| 50 | .\" |
| 51 | .\" If the F register is turned on, we'll generate index entries on stderr for |
| 52 | .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index |
| 53 | .\" entries marked with X<> in POD. Of course, you'll have to process the |
| 54 | .\" output yourself in some meaningful fashion. |
| 55 | .if \nF \{\ |
| 56 | . de IX |
| 57 | . tm Index:\\$1\t\\n%\t"\\$2" |
| 58 | .. |
| 59 | . nr % 0 |
| 60 | . rr F |
| 61 | .\} |
| 62 | .\" |
| 63 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 64 | .\" way too many mistakes in technical documents. |
| 65 | .hy 0 |
| 66 | .if n .na |
| 67 | .\" |
| 68 | .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). |
| 69 | .\" Fear. Run. Save yourself. No user-serviceable parts. |
| 70 | . \" fudge factors for nroff and troff |
| 71 | .if n \{\ |
| 72 | . ds #H 0 |
| 73 | . ds #V .8m |
| 74 | . ds #F .3m |
| 75 | . ds #[ \f1 |
| 76 | . ds #] \fP |
| 77 | .\} |
| 78 | .if t \{\ |
| 79 | . ds #H ((1u-(\\\\n(.fu%2u))*.13m) |
| 80 | . ds #V .6m |
| 81 | . ds #F 0 |
| 82 | . ds #[ \& |
| 83 | . ds #] \& |
| 84 | .\} |
| 85 | . \" simple accents for nroff and troff |
| 86 | .if n \{\ |
| 87 | . ds ' \& |
| 88 | . ds ` \& |
| 89 | . ds ^ \& |
| 90 | . ds , \& |
| 91 | . ds ~ ~ |
| 92 | . ds / |
| 93 | .\} |
| 94 | .if t \{\ |
| 95 | . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" |
| 96 | . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' |
| 97 | . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' |
| 98 | . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' |
| 99 | . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' |
| 100 | . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' |
| 101 | .\} |
| 102 | . \" troff and (daisy-wheel) nroff accents |
| 103 | .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' |
| 104 | .ds 8 \h'\*(#H'\(*b\h'-\*(#H' |
| 105 | .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] |
| 106 | .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' |
| 107 | .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' |
| 108 | .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] |
| 109 | .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] |
| 110 | .ds ae a\h'-(\w'a'u*4/10)'e |
| 111 | .ds Ae A\h'-(\w'A'u*4/10)'E |
| 112 | . \" corrections for vroff |
| 113 | .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' |
| 114 | .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' |
| 115 | . \" for low resolution devices (crt and lpr) |
| 116 | .if \n(.H>23 .if \n(.V>19 \ |
| 117 | \{\ |
| 118 | . ds : e |
| 119 | . ds 8 ss |
| 120 | . ds o a |
| 121 | . ds d- d\h'-1'\(ga |
| 122 | . ds D- D\h'-1'\(hy |
| 123 | . ds th \o'bp' |
| 124 | . ds Th \o'LP' |
| 125 | . ds ae ae |
| 126 | . ds Ae AE |
| 127 | .\} |
| 128 | .rm #[ #] #H #V #F C |
| 129 | .\" ======================================================================== |
| 130 | .\" |
| 131 | .IX Title "PERLFAQ3 1" |
| 132 | .TH PERLFAQ3 1 "2002-06-08" "perl v5.8.0" "Perl Programmers Reference Guide" |
| 133 | .SH "NAME" |
| 134 | perlfaq3 \- Programming Tools ($Revision: 1.22 $, $Date: 2002/05/06 13:11:13 $) |
| 135 | .SH "DESCRIPTION" |
| 136 | .IX Header "DESCRIPTION" |
| 137 | This section of the \s-1FAQ\s0 answers questions related to programmer tools |
| 138 | and programming support. |
| 139 | .Sh "How do I do (anything)?" |
| 140 | .IX Subsection "How do I do (anything)?" |
| 141 | Have you looked at \s-1CPAN\s0 (see perlfaq2)? The chances are that |
| 142 | someone has already written a module that can solve your problem. |
| 143 | Have you read the appropriate manpages? Here's a brief index: |
| 144 | .PP |
| 145 | .Vb 12 |
| 146 | \& Basics perldata, perlvar, perlsyn, perlop, perlsub |
| 147 | \& Execution perlrun, perldebug |
| 148 | \& Functions perlfunc |
| 149 | \& Objects perlref, perlmod, perlobj, perltie |
| 150 | \& Data Structures perlref, perllol, perldsc |
| 151 | \& Modules perlmod, perlmodlib, perlsub |
| 152 | \& Regexes perlre, perlfunc, perlop, perllocale |
| 153 | \& Moving to perl5 perltrap, perl |
| 154 | \& Linking w/C perlxstut, perlxs, perlcall, perlguts, perlembed |
| 155 | \& Various http://www.cpan.org/misc/olddoc/FMTEYEWTK.tgz |
| 156 | \& (not a man-page but still useful, a collection |
| 157 | \& of various essays on Perl techniques) |
| 158 | .Ve |
| 159 | .PP |
| 160 | A crude table of contents for the Perl manpage set is found in perltoc. |
| 161 | .Sh "How can I use Perl interactively?" |
| 162 | .IX Subsection "How can I use Perl interactively?" |
| 163 | The typical approach uses the Perl debugger, described in the |
| 164 | \&\fIperldebug\fR\|(1) manpage, on an ``empty'' program, like this: |
| 165 | .PP |
| 166 | .Vb 1 |
| 167 | \& perl -de 42 |
| 168 | .Ve |
| 169 | .PP |
| 170 | Now just type in any legal Perl code, and it will be immediately |
| 171 | evaluated. You can also examine the symbol table, get stack |
| 172 | backtraces, check variable values, set breakpoints, and other |
| 173 | operations typically found in symbolic debuggers. |
| 174 | .Sh "Is there a Perl shell?" |
| 175 | .IX Subsection "Is there a Perl shell?" |
| 176 | In general, not yet. There is psh available at |
| 177 | .PP |
| 178 | .Vb 1 |
| 179 | \& http://www.focusresearch.com/gregor/psh |
| 180 | .Ve |
| 181 | .PP |
| 182 | Which includes the following description: |
| 183 | .PP |
| 184 | .Vb 5 |
| 185 | \& The Perl Shell is a shell that combines the interactive nature |
| 186 | \& of a Unix shell with the power of Perl. The goal is to eventually |
| 187 | \& have a full featured shell that behaves as expected for normal |
| 188 | \& shell activity. But, the Perl Shell will use Perl syntax and |
| 189 | \& functionality for control-flow statements and other things. |
| 190 | .Ve |
| 191 | .PP |
| 192 | The Shell.pm module (distributed with Perl) makes Perl try commands |
| 193 | which aren't part of the Perl language as shell commands. perlsh |
| 194 | from the source distribution is simplistic and uninteresting, but |
| 195 | may still be what you want. |
| 196 | .Sh "How do I debug my Perl programs?" |
| 197 | .IX Subsection "How do I debug my Perl programs?" |
| 198 | Have you tried \f(CW\*(C`use warnings\*(C'\fR or used \f(CW\*(C`\-w\*(C'\fR? They enable warnings |
| 199 | to detect dubious practices. |
| 200 | .PP |
| 201 | Have you tried \f(CW\*(C`use strict\*(C'\fR? It prevents you from using symbolic |
| 202 | references, makes you predeclare any subroutines that you call as bare |
| 203 | words, and (probably most importantly) forces you to predeclare your |
| 204 | variables with \f(CW\*(C`my\*(C'\fR, \f(CW\*(C`our\*(C'\fR, or \f(CW\*(C`use vars\*(C'\fR. |
| 205 | .PP |
| 206 | Did you check the return values of each and every system call? The operating |
| 207 | system (and thus Perl) tells you whether they worked, and if not |
| 208 | why. |
| 209 | .PP |
| 210 | .Vb 2 |
| 211 | \& open(FH, "> /etc/cantwrite") |
| 212 | \& or die "Couldn't write to /etc/cantwrite: $!\en"; |
| 213 | .Ve |
| 214 | .PP |
| 215 | Did you read perltrap? It's full of gotchas for old and new Perl |
| 216 | programmers and even has sections for those of you who are upgrading |
| 217 | from languages like \fIawk\fR and \fIC\fR. |
| 218 | .PP |
| 219 | Have you tried the Perl debugger, described in perldebug? You can |
| 220 | step through your program and see what it's doing and thus work out |
| 221 | why what it's doing isn't what it should be doing. |
| 222 | .Sh "How do I profile my Perl programs?" |
| 223 | .IX Subsection "How do I profile my Perl programs?" |
| 224 | You should get the Devel::DProf module from the standard distribution |
| 225 | (or separately on \s-1CPAN\s0) and also use Benchmark.pm from the standard |
| 226 | distribution. The Benchmark module lets you time specific portions of |
| 227 | your code, while Devel::DProf gives detailed breakdowns of where your |
| 228 | code spends its time. |
| 229 | .PP |
| 230 | Here's a sample use of Benchmark: |
| 231 | .PP |
| 232 | .Vb 1 |
| 233 | \& use Benchmark; |
| 234 | .Ve |
| 235 | .PP |
| 236 | .Vb 2 |
| 237 | \& @junk = `cat /etc/motd`; |
| 238 | \& $count = 10_000; |
| 239 | .Ve |
| 240 | .PP |
| 241 | .Vb 10 |
| 242 | \& timethese($count, { |
| 243 | \& 'map' => sub { my @a = @junk; |
| 244 | \& map { s/a/b/ } @a; |
| 245 | \& return @a |
| 246 | \& }, |
| 247 | \& 'for' => sub { my @a = @junk; |
| 248 | \& local $_; |
| 249 | \& for (@a) { s/a/b/ }; |
| 250 | \& return @a }, |
| 251 | \& }); |
| 252 | .Ve |
| 253 | .PP |
| 254 | This is what it prints (on one machine\*(--your results will be dependent |
| 255 | on your hardware, operating system, and the load on your machine): |
| 256 | .PP |
| 257 | .Vb 3 |
| 258 | \& Benchmark: timing 10000 iterations of for, map... |
| 259 | \& for: 4 secs ( 3.97 usr 0.01 sys = 3.98 cpu) |
| 260 | \& map: 6 secs ( 4.97 usr 0.00 sys = 4.97 cpu) |
| 261 | .Ve |
| 262 | .PP |
| 263 | Be aware that a good benchmark is very hard to write. It only tests the |
| 264 | data you give it and proves little about the differing complexities |
| 265 | of contrasting algorithms. |
| 266 | .Sh "How do I cross-reference my Perl programs?" |
| 267 | .IX Subsection "How do I cross-reference my Perl programs?" |
| 268 | The B::Xref module can be used to generate cross-reference reports |
| 269 | for Perl programs. |
| 270 | .PP |
| 271 | .Vb 1 |
| 272 | \& perl -MO=Xref[,OPTIONS] scriptname.plx |
| 273 | .Ve |
| 274 | .Sh "Is there a pretty-printer (formatter) for Perl?" |
| 275 | .IX Subsection "Is there a pretty-printer (formatter) for Perl?" |
| 276 | Perltidy is a Perl script which indents and reformats Perl scripts |
| 277 | to make them easier to read by trying to follow the rules of the |
| 278 | perlstyle. If you write Perl scripts, or spend much time reading |
| 279 | them, you will probably find it useful. It is available at |
| 280 | http://perltidy.sourceforge.net |
| 281 | .PP |
| 282 | Of course, if you simply follow the guidelines in perlstyle, |
| 283 | you shouldn't need to reformat. The habit of formatting your code |
| 284 | as you write it will help prevent bugs. Your editor can and should |
| 285 | help you with this. The perl-mode or newer cperl-mode for emacs |
| 286 | can provide remarkable amounts of help with most (but not all) |
| 287 | code, and even less programmable editors can provide significant |
| 288 | assistance. Tom Christiansen and many other \s-1VI\s0 users swear by |
| 289 | the following settings in vi and its clones: |
| 290 | .PP |
| 291 | .Vb 2 |
| 292 | \& set ai sw=4 |
| 293 | \& map! ^O {^M}^[O^T |
| 294 | .Ve |
| 295 | .PP |
| 296 | Put that in your \fI.exrc\fR file (replacing the caret characters |
| 297 | with control characters) and away you go. In insert mode, ^T is |
| 298 | for indenting, ^D is for undenting, and ^O is for blockdenting\*(-- |
| 299 | as it were. A more complete example, with comments, can be found at |
| 300 | http://www.cpan.org/authors/id/TOMC/scripts/toms.exrc.gz |
| 301 | .PP |
| 302 | The a2ps http://www\-inf.enst.fr/%7Edemaille/a2ps/black+white.ps does |
| 303 | lots of things related to generating nicely printed output of |
| 304 | documents, as does enscript at http://people.ssh.fi/mtr/genscript/ . |
| 305 | .Sh "Is there a ctags for Perl?" |
| 306 | .IX Subsection "Is there a ctags for Perl?" |
| 307 | Recent versions of ctags do much more than older versions did. |
| 308 | \&\s-1EXUBERANT\s0 \s-1CTAGS\s0 is available from http://ctags.sourceforge.net/ |
| 309 | and does a good job of making tags files for perl code. |
| 310 | .PP |
| 311 | There is also a simple one at |
| 312 | http://www.cpan.org/authors/id/TOMC/scripts/ptags.gz which may do |
| 313 | the trick. It can be easy to hack this into what you want. |
| 314 | .Sh "Is there an \s-1IDE\s0 or Windows Perl Editor?" |
| 315 | .IX Subsection "Is there an IDE or Windows Perl Editor?" |
| 316 | Perl programs are just plain text, so any editor will do. |
| 317 | .PP |
| 318 | If you're on Unix, you already have an IDE\*(--Unix itself. The \s-1UNIX\s0 |
| 319 | philosophy is the philosophy of several small tools that each do one |
| 320 | thing and do it well. It's like a carpenter's toolbox. |
| 321 | .PP |
| 322 | If you want an \s-1IDE\s0, check the following: |
| 323 | .IP "Komodo" 4 |
| 324 | .IX Item "Komodo" |
| 325 | ActiveState's cross-platform (as of April 2001 Windows and Linux), |
| 326 | multi-language \s-1IDE\s0 has Perl support, including a regular expression |
| 327 | debugger and remote debugging |
| 328 | ( http://www.ActiveState.com/Products/Komodo/index.html ). (Visual |
| 329 | Perl, a Visual Studio.NET plug-in is currently (early 2001) in beta |
| 330 | ( http://www.ActiveState.com/Products/VisualPerl/index.html )). |
| 331 | .IP "The Object System" 4 |
| 332 | .IX Item "The Object System" |
| 333 | ( http://www.castlelink.co.uk/object_system/ ) is a Perl web |
| 334 | applications development \s-1IDE\s0, apparently for any platform |
| 335 | that runs Perl. |
| 336 | .IP "Open Perl \s-1IDE\s0" 4 |
| 337 | .IX Item "Open Perl IDE" |
| 338 | ( http://open\-perl\-ide.sourceforge.net/ ) |
| 339 | Open Perl \s-1IDE\s0 is an integrated development environment for writing |
| 340 | and debugging Perl scripts with ActiveState's ActivePerl distribution |
| 341 | under Windows 95/98/NT/2000. |
| 342 | .IP "PerlBuilder" 4 |
| 343 | .IX Item "PerlBuilder" |
| 344 | ( http://www.solutionsoft.com/perl.htm ) is an integrated development |
| 345 | environment for Windows that supports Perl development. |
| 346 | .IP "visiPerl+" 4 |
| 347 | .IX Item "visiPerl+" |
| 348 | ( http://helpconsulting.net/visiperl/ ) |
| 349 | From Help Consulting, for Windows. |
| 350 | .IP "OptiPerl" 4 |
| 351 | .IX Item "OptiPerl" |
| 352 | ( http://www.optiperl.com/ ) is a Windows \s-1IDE\s0 with simulated \s-1CGI\s0 |
| 353 | environment, including debugger and syntax highlighting editor. |
| 354 | .PP |
| 355 | For Windows there's also the |
| 356 | .IP "CodeMagicCD" 4 |
| 357 | .IX Item "CodeMagicCD" |
| 358 | ( http://www.codemagiccd.com/ ) Collection of various programming |
| 359 | tools for Windows: Perl (5.005_03), TclTk, Python, \s-1GNU\s0 programming |
| 360 | tools, \s-1REBOL\s0, wxWindows toolkit, the MinGW \s-1GNU\s0 C/\*(C+ compiler, \s-1DJGPP\s0 |
| 361 | \&\s-1GNU\s0 C/\*(C+ compiler, Cint C interpreter, YaBasic. |
| 362 | .PP |
| 363 | For editors: if you're on Unix you probably have vi or a vi clone already, |
| 364 | and possibly an emacs too, so you may not need to download anything. |
| 365 | In any emacs the cperl-mode (M\-x cperl\-mode) gives you perhaps the |
| 366 | best available Perl editing mode in any editor. |
| 367 | .PP |
| 368 | If you are using Windows, you can use any editor that lets |
| 369 | you work with plain text, such as NotePad or WordPad. Word |
| 370 | processors, such as Microsoft Word or WordPerfect, typically |
| 371 | do not work since they insert all sorts of behind-the-scenes |
| 372 | information, although some allow you to save files as \*(L"Text |
| 373 | Only\*(R". You can also download text editors designed |
| 374 | specifically for programming, such as Textpad |
| 375 | ( http://www.textpad.com/ ) and UltraEdit |
| 376 | ( http://www.ultraedit.com/ ), among others. |
| 377 | .PP |
| 378 | If you are using Mac \s-1OS\s0, the same concerns apply. MacPerl |
| 379 | (for Classic environments) comes with a simple editor. |
| 380 | Popular external editors are BBEdit ( http://www.bbedit.com/ ) |
| 381 | or Alpha ( http://www.kelehers.org/alpha/ ). Mac \s-1OS\s0 X users can |
| 382 | use Unix editors as well. |
| 383 | .IP "\s-1GNU\s0 Emacs" 4 |
| 384 | .IX Item "GNU Emacs" |
| 385 | http://www.gnu.org/software/emacs/windows/ntemacs.html |
| 386 | .IP "MicroEMACS" 4 |
| 387 | .IX Item "MicroEMACS" |
| 388 | http://members.nbci.com/uemacs/ |
| 389 | .IP "XEmacs" 4 |
| 390 | .IX Item "XEmacs" |
| 391 | http://www.xemacs.org/Download/index.html |
| 392 | .PP |
| 393 | or a vi clone such as |
| 394 | .IP "Elvis" 4 |
| 395 | .IX Item "Elvis" |
| 396 | ftp://ftp.cs.pdx.edu/pub/elvis/ http://www.fh\-wedel.de/elvis/ |
| 397 | .IP "Vile" 4 |
| 398 | .IX Item "Vile" |
| 399 | http://vile.cx/ |
| 400 | .IP "Vim" 4 |
| 401 | .IX Item "Vim" |
| 402 | http://www.vim.org/ |
| 403 | .Sp |
| 404 | win32: http://www.cs.vu.nl/%7Etmgil/vi.html |
| 405 | .PP |
| 406 | For vi lovers in general, Windows or elsewhere: |
| 407 | .PP |
| 408 | .Vb 1 |
| 409 | \& http://www.thomer.com/thomer/vi/vi.html |
| 410 | .Ve |
| 411 | .PP |
| 412 | nvi ( http://www.bostic.com/vi/ , available from \s-1CPAN\s0 in src/misc/) is |
| 413 | yet another vi clone, unfortunately not available for Windows, but in |
| 414 | \&\s-1UNIX\s0 platforms you might be interested in trying it out, firstly because |
| 415 | strictly speaking it is not a vi clone, it is the real vi, or the new |
| 416 | incarnation of it, and secondly because you can embed Perl inside it |
| 417 | to use Perl as the scripting language. nvi is not alone in this, |
| 418 | though: at least also vim and vile offer an embedded Perl. |
| 419 | .PP |
| 420 | The following are Win32 multilanguage editor/IDESs that support Perl: |
| 421 | .IP "Codewright" 4 |
| 422 | .IX Item "Codewright" |
| 423 | http://www.starbase.com/ |
| 424 | .IP "MultiEdit" 4 |
| 425 | .IX Item "MultiEdit" |
| 426 | http://www.MultiEdit.com/ |
| 427 | .IP "SlickEdit" 4 |
| 428 | .IX Item "SlickEdit" |
| 429 | http://www.slickedit.com/ |
| 430 | .PP |
| 431 | There is also a toyedit Text widget based editor written in Perl |
| 432 | that is distributed with the Tk module on \s-1CPAN\s0. The ptkdb |
| 433 | ( http://world.std.com/~aep/ptkdb/ ) is a Perl/tk based debugger that |
| 434 | acts as a development environment of sorts. Perl Composer |
| 435 | ( http://perlcomposer.sourceforge.net/vperl.html ) is an \s-1IDE\s0 for Perl/Tk |
| 436 | \&\s-1GUI\s0 creation. |
| 437 | .PP |
| 438 | In addition to an editor/IDE you might be interested in a more |
| 439 | powerful shell environment for Win32. Your options include |
| 440 | .IP "Bash" 4 |
| 441 | .IX Item "Bash" |
| 442 | from the Cygwin package ( http://sources.redhat.com/cygwin/ ) |
| 443 | .IP "Ksh" 4 |
| 444 | .IX Item "Ksh" |
| 445 | from the \s-1MKS\s0 Toolkit ( http://www.mks.com/ ), or the Bourne shell of |
| 446 | the U/WIN environment ( http://www.research.att.com/sw/tools/uwin/ ) |
| 447 | .IP "Tcsh" 4 |
| 448 | .IX Item "Tcsh" |
| 449 | ftp://ftp.astron.com/pub/tcsh/ , see also |
| 450 | http://www.primate.wisc.edu/software/csh\-tcsh\-book/ |
| 451 | .IP "Zsh" 4 |
| 452 | .IX Item "Zsh" |
| 453 | ftp://ftp.blarg.net/users/amol/zsh/ , see also http://www.zsh.org/ |
| 454 | .PP |
| 455 | \&\s-1MKS\s0 and U/WIN are commercial (U/WIN is free for educational and |
| 456 | research purposes), Cygwin is covered by the \s-1GNU\s0 Public License (but |
| 457 | that shouldn't matter for Perl use). The Cygwin, \s-1MKS\s0, and U/WIN all |
| 458 | contain (in addition to the shells) a comprehensive set of standard |
| 459 | \&\s-1UNIX\s0 toolkit utilities. |
| 460 | .PP |
| 461 | If you're transferring text files between Unix and Windows using \s-1FTP\s0 |
| 462 | be sure to transfer them in \s-1ASCII\s0 mode so the ends of lines are |
| 463 | appropriately converted. |
| 464 | .PP |
| 465 | On Mac \s-1OS\s0 the MacPerl Application comes with a simple 32k text editor |
| 466 | that behaves like a rudimentary \s-1IDE\s0. In contrast to the MacPerl Application |
| 467 | the \s-1MPW\s0 Perl tool can make use of the \s-1MPW\s0 Shell itself as an editor (with |
| 468 | no 32k limit). |
| 469 | .IP "BBEdit and BBEdit Lite" 4 |
| 470 | .IX Item "BBEdit and BBEdit Lite" |
| 471 | are text editors for Mac \s-1OS\s0 that have a Perl sensitivity mode |
| 472 | ( http://web.barebones.com/ ). |
| 473 | .IP "Alpha" 4 |
| 474 | .IX Item "Alpha" |
| 475 | is an editor, written and extensible in Tcl, that nonetheless has |
| 476 | built in support for several popular markup and programming languages |
| 477 | including Perl and \s-1HTML\s0 ( http://alpha.olm.net/ ). |
| 478 | .PP |
| 479 | Pepper and Pe are programming language sensitive text editors for Mac |
| 480 | \&\s-1OS\s0 X and BeOS respectively ( http://www.hekkelman.com/ ). |
| 481 | .Sh "Where can I get Perl macros for vi?" |
| 482 | .IX Subsection "Where can I get Perl macros for vi?" |
| 483 | For a complete version of Tom Christiansen's vi configuration file, |
| 484 | see http://www.cpan.org/authors/Tom_Christiansen/scripts/toms.exrc.gz , |
| 485 | the standard benchmark file for vi emulators. The file runs best with nvi, |
| 486 | the current version of vi out of Berkeley, which incidentally can be built |
| 487 | with an embedded Perl interpreter\*(--see http://www.cpan.org/src/misc/ . |
| 488 | .Sh "Where can I get perl-mode for emacs?" |
| 489 | .IX Subsection "Where can I get perl-mode for emacs?" |
| 490 | Since Emacs version 19 patchlevel 22 or so, there have been both a |
| 491 | perl\-mode.el and support for the Perl debugger built in. These should |
| 492 | come with the standard Emacs 19 distribution. |
| 493 | .PP |
| 494 | In the Perl source directory, you'll find a directory called \*(L"emacs\*(R", |
| 495 | which contains a cperl-mode that color-codes keywords, provides |
| 496 | context-sensitive help, and other nifty things. |
| 497 | .PP |
| 498 | Note that the perl-mode of emacs will have fits with \f(CW"main'foo"\fR |
| 499 | (single quote), and mess up the indentation and highlighting. You |
| 500 | are probably using \f(CW"main::foo"\fR in new Perl code anyway, so this |
| 501 | shouldn't be an issue. |
| 502 | .Sh "How can I use curses with Perl?" |
| 503 | .IX Subsection "How can I use curses with Perl?" |
| 504 | The Curses module from \s-1CPAN\s0 provides a dynamically loadable object |
| 505 | module interface to a curses library. A small demo can be found at the |
| 506 | directory http://www.cpan.org/authors/Tom_Christiansen/scripts/rep ; |
| 507 | this program repeats a command and updates the screen as needed, rendering |
| 508 | \&\fBrep ps axu\fR similar to \fBtop\fR. |
| 509 | .Sh "How can I use X or Tk with Perl?" |
| 510 | .IX Subsection "How can I use X or Tk with Perl?" |
| 511 | Tk is a completely Perl\-based, object-oriented interface to the Tk toolkit |
| 512 | that doesn't force you to use Tcl just to get at Tk. Sx is an interface |
| 513 | to the Athena Widget set. Both are available from \s-1CPAN\s0. See the |
| 514 | directory http://www.cpan.org/modules/by\-category/08_User_Interfaces/ |
| 515 | .PP |
| 516 | Invaluable for Perl/Tk programming are the Perl/Tk \s-1FAQ\s0 at |
| 517 | http://w4.lns.cornell.edu/%7Epvhp/ptk/ptkTOC.html , the Perl/Tk Reference |
| 518 | Guide available at |
| 519 | http://www.cpan.org/authors/Stephen_O_Lidie/ , and the |
| 520 | online manpages at |
| 521 | http://www\-users.cs.umn.edu/%7Eamundson/perl/perltk/toc.html . |
| 522 | .Sh "How can I generate simple menus without using \s-1CGI\s0 or Tk?" |
| 523 | .IX Subsection "How can I generate simple menus without using CGI or Tk?" |
| 524 | The http://www.cpan.org/authors/id/SKUNZ/perlmenu.v4.0.tar.gz |
| 525 | module, which is curses\-based, can help with this. |
| 526 | .Sh "How can I make my Perl program run faster?" |
| 527 | .IX Subsection "How can I make my Perl program run faster?" |
| 528 | The best way to do this is to come up with a better algorithm. This |
| 529 | can often make a dramatic difference. Jon Bentley's book |
| 530 | ``Programming Pearls'' (that's not a misspelling!) has some good tips |
| 531 | on optimization, too. Advice on benchmarking boils down to: benchmark |
| 532 | and profile to make sure you're optimizing the right part, look for |
| 533 | better algorithms instead of microtuning your code, and when all else |
| 534 | fails consider just buying faster hardware. You will probably want to |
| 535 | read the answer to the earlier question ``How do I profile my Perl programs?'' |
| 536 | if you haven't done so already. |
| 537 | .PP |
| 538 | A different approach is to autoload seldom-used Perl code. See the |
| 539 | AutoSplit and AutoLoader modules in the standard distribution for |
| 540 | that. Or you could locate the bottleneck and think about writing just |
| 541 | that part in C, the way we used to take bottlenecks in C code and |
| 542 | write them in assembler. Similar to rewriting in C, |
| 543 | modules that have critical sections can be written in C (for instance, the |
| 544 | \&\s-1PDL\s0 module from \s-1CPAN\s0). |
| 545 | .PP |
| 546 | In some cases, it may be worth it to use the backend compiler to |
| 547 | produce byte code (saving compilation time) or compile into C, which |
| 548 | will certainly save compilation time and sometimes a small amount (but |
| 549 | not much) execution time. See the question about compiling your Perl |
| 550 | programs for more on the compiler\*(--the wins aren't as obvious as you'd |
| 551 | hope. |
| 552 | .PP |
| 553 | If you're currently linking your perl executable to a shared \fIlibc.so\fR, |
| 554 | you can often gain a 10\-25% performance benefit by rebuilding it to |
| 555 | link with a static libc.a instead. This will make a bigger perl |
| 556 | executable, but your Perl programs (and programmers) may thank you for |
| 557 | it. See the \fI\s-1INSTALL\s0\fR file in the source distribution for more |
| 558 | information. |
| 559 | .PP |
| 560 | Unsubstantiated reports allege that Perl interpreters that use sfio |
| 561 | outperform those that don't (for I/O intensive applications). To try |
| 562 | this, see the \fI\s-1INSTALL\s0\fR file in the source distribution, especially |
| 563 | the ``Selecting File I/O mechanisms'' section. |
| 564 | .PP |
| 565 | The undump program was an old attempt to speed up your Perl program |
| 566 | by storing the already-compiled form to disk. This is no longer |
| 567 | a viable option, as it only worked on a few architectures, and |
| 568 | wasn't a good solution anyway. |
| 569 | .Sh "How can I make my Perl program take less memory?" |
| 570 | .IX Subsection "How can I make my Perl program take less memory?" |
| 571 | When it comes to time-space tradeoffs, Perl nearly always prefers to |
| 572 | throw memory at a problem. Scalars in Perl use more memory than |
| 573 | strings in C, arrays take more than that, and hashes use even more. While |
| 574 | there's still a lot to be done, recent releases have been addressing |
| 575 | these issues. For example, as of 5.004, duplicate hash keys are |
| 576 | shared amongst all hashes using them, so require no reallocation. |
| 577 | .PP |
| 578 | In some cases, using \fIsubstr()\fR or \fIvec()\fR to simulate arrays can be |
| 579 | highly beneficial. For example, an array of a thousand booleans will |
| 580 | take at least 20,000 bytes of space, but it can be turned into one |
| 581 | 125\-byte bit vector\*(--a considerable memory savings. The standard |
| 582 | Tie::SubstrHash module can also help for certain types of data |
| 583 | structure. If you're working with specialist data structures |
| 584 | (matrices, for instance) modules that implement these in C may use |
| 585 | less memory than equivalent Perl modules. |
| 586 | .PP |
| 587 | Another thing to try is learning whether your Perl was compiled with |
| 588 | the system malloc or with Perl's builtin malloc. Whichever one it |
| 589 | is, try using the other one and see whether this makes a difference. |
| 590 | Information about malloc is in the \fI\s-1INSTALL\s0\fR file in the source |
| 591 | distribution. You can find out whether you are using perl's malloc by |
| 592 | typing \f(CW\*(C`perl \-V:usemymalloc\*(C'\fR. |
| 593 | .PP |
| 594 | Of course, the best way to save memory is to not do anything to waste |
| 595 | it in the first place. Good programming practices can go a long way |
| 596 | toward this: |
| 597 | .IP "\(bu Don't slurp!" 4 |
| 598 | .IX Item "Don't slurp!" |
| 599 | Don't read an entire file into memory if you can process it line |
| 600 | by line. Or more concretely, use a loop like this: |
| 601 | .Sp |
| 602 | .Vb 6 |
| 603 | \& # |
| 604 | \& # Good Idea |
| 605 | \& # |
| 606 | \& while (<FILE>) { |
| 607 | \& # ... |
| 608 | \& } |
| 609 | .Ve |
| 610 | .Sp |
| 611 | instead of this: |
| 612 | .Sp |
| 613 | .Vb 7 |
| 614 | \& # |
| 615 | \& # Bad Idea |
| 616 | \& # |
| 617 | \& @data = <FILE>; |
| 618 | \& foreach (@data) { |
| 619 | \& # ... |
| 620 | \& } |
| 621 | .Ve |
| 622 | .Sp |
| 623 | When the files you're processing are small, it doesn't much matter which |
| 624 | way you do it, but it makes a huge difference when they start getting |
| 625 | larger. |
| 626 | .IP "\(bu Use map and grep selectively" 4 |
| 627 | .IX Item "Use map and grep selectively" |
| 628 | Remember that both map and grep expect a \s-1LIST\s0 argument, so doing this: |
| 629 | .Sp |
| 630 | .Vb 1 |
| 631 | \& @wanted = grep {/pattern/} <FILE>; |
| 632 | .Ve |
| 633 | .Sp |
| 634 | will cause the entire file to be slurped. For large files, it's better |
| 635 | to loop: |
| 636 | .Sp |
| 637 | .Vb 3 |
| 638 | \& while (<FILE>) { |
| 639 | \& push(@wanted, $_) if /pattern/; |
| 640 | \& } |
| 641 | .Ve |
| 642 | .IP "\(bu Avoid unnecessary quotes and stringification" 4 |
| 643 | .IX Item "Avoid unnecessary quotes and stringification" |
| 644 | Don't quote large strings unless absolutely necessary: |
| 645 | .Sp |
| 646 | .Vb 1 |
| 647 | \& my $copy = "$large_string"; |
| 648 | .Ve |
| 649 | .Sp |
| 650 | makes 2 copies of \f(CW$large_string\fR (one for \f(CW$copy\fR and another for the |
| 651 | quotes), whereas |
| 652 | .Sp |
| 653 | .Vb 1 |
| 654 | \& my $copy = $large_string; |
| 655 | .Ve |
| 656 | .Sp |
| 657 | only makes one copy. |
| 658 | .Sp |
| 659 | Ditto for stringifying large arrays: |
| 660 | .Sp |
| 661 | .Vb 4 |
| 662 | \& { |
| 663 | \& local $, = "\en"; |
| 664 | \& print @big_array; |
| 665 | \& } |
| 666 | .Ve |
| 667 | .Sp |
| 668 | is much more memory-efficient than either |
| 669 | .Sp |
| 670 | .Vb 1 |
| 671 | \& print join "\en", @big_array; |
| 672 | .Ve |
| 673 | .Sp |
| 674 | or |
| 675 | .Sp |
| 676 | .Vb 4 |
| 677 | \& { |
| 678 | \& local $" = "\en"; |
| 679 | \& print "@big_array"; |
| 680 | \& } |
| 681 | .Ve |
| 682 | .IP "\(bu Pass by reference" 4 |
| 683 | .IX Item "Pass by reference" |
| 684 | Pass arrays and hashes by reference, not by value. For one thing, it's |
| 685 | the only way to pass multiple lists or hashes (or both) in a single |
| 686 | call/return. It also avoids creating a copy of all the contents. This |
| 687 | requires some judgment, however, because any changes will be propagated |
| 688 | back to the original data. If you really want to mangle (er, modify) a |
| 689 | copy, you'll have to sacrifice the memory needed to make one. |
| 690 | .IP "\(bu Tie large variables to disk." 4 |
| 691 | .IX Item "Tie large variables to disk." |
| 692 | For \*(L"big\*(R" data stores (i.e. ones that exceed available memory) consider |
| 693 | using one of the \s-1DB\s0 modules to store it on disk instead of in \s-1RAM\s0. This |
| 694 | will incur a penalty in access time, but that's probably better than |
| 695 | causing your hard disk to thrash due to massive swapping. |
| 696 | .Sh "Is it unsafe to return a pointer to local data?" |
| 697 | .IX Subsection "Is it unsafe to return a pointer to local data?" |
| 698 | No, Perl's garbage collection system takes care of this. |
| 699 | .PP |
| 700 | .Vb 4 |
| 701 | \& sub makeone { |
| 702 | \& my @a = ( 1 .. 10 ); |
| 703 | \& return \e@a; |
| 704 | \& } |
| 705 | .Ve |
| 706 | .PP |
| 707 | .Vb 3 |
| 708 | \& for $i ( 1 .. 10 ) { |
| 709 | \& push @many, makeone(); |
| 710 | \& } |
| 711 | .Ve |
| 712 | .PP |
| 713 | .Vb 1 |
| 714 | \& print $many[4][5], "\en"; |
| 715 | .Ve |
| 716 | .PP |
| 717 | .Vb 1 |
| 718 | \& print "@many\en"; |
| 719 | .Ve |
| 720 | .Sh "How can I free an array or hash so my program shrinks?" |
| 721 | .IX Subsection "How can I free an array or hash so my program shrinks?" |
| 722 | You usually can't. On most operating systems, memory |
| 723 | allocated to a program can never be returned to the system. |
| 724 | That's why long-running programs sometimes re-exec |
| 725 | themselves. Some operating systems (notably, systems that |
| 726 | use \fImmap\fR\|(2) for allocating large chunks of memory) can |
| 727 | reclaim memory that is no longer used, but on such systems, |
| 728 | perl must be configured and compiled to use the \s-1OS\s0's malloc, |
| 729 | not perl's. |
| 730 | .PP |
| 731 | However, judicious use of \fImy()\fR on your variables will help make sure |
| 732 | that they go out of scope so that Perl can free up that space for |
| 733 | use in other parts of your program. A global variable, of course, never |
| 734 | goes out of scope, so you can't get its space automatically reclaimed, |
| 735 | although \fIundef()\fRing and/or \fIdelete()\fRing it will achieve the same effect. |
| 736 | In general, memory allocation and de-allocation isn't something you can |
| 737 | or should be worrying about much in Perl, but even this capability |
| 738 | (preallocation of data types) is in the works. |
| 739 | .Sh "How can I make my \s-1CGI\s0 script more efficient?" |
| 740 | .IX Subsection "How can I make my CGI script more efficient?" |
| 741 | Beyond the normal measures described to make general Perl programs |
| 742 | faster or smaller, a \s-1CGI\s0 program has additional issues. It may be run |
| 743 | several times per second. Given that each time it runs it will need |
| 744 | to be re-compiled and will often allocate a megabyte or more of system |
| 745 | memory, this can be a killer. Compiling into C \fBisn't going to help |
| 746 | you\fR because the process start-up overhead is where the bottleneck is. |
| 747 | .PP |
| 748 | There are two popular ways to avoid this overhead. One solution |
| 749 | involves running the Apache \s-1HTTP\s0 server (available from |
| 750 | http://www.apache.org/ ) with either of the mod_perl or mod_fastcgi |
| 751 | plugin modules. |
| 752 | .PP |
| 753 | With mod_perl and the Apache::Registry module (distributed with |
| 754 | mod_perl), httpd will run with an embedded Perl interpreter which |
| 755 | pre-compiles your script and then executes it within the same address |
| 756 | space without forking. The Apache extension also gives Perl access to |
| 757 | the internal server \s-1API\s0, so modules written in Perl can do just about |
| 758 | anything a module written in C can. For more on mod_perl, see |
| 759 | http://perl.apache.org/ |
| 760 | .PP |
| 761 | With the \s-1FCGI\s0 module (from \s-1CPAN\s0) and the mod_fastcgi |
| 762 | module (available from http://www.fastcgi.com/ ) each of your Perl |
| 763 | programs becomes a permanent \s-1CGI\s0 daemon process. |
| 764 | .PP |
| 765 | Both of these solutions can have far-reaching effects on your system |
| 766 | and on the way you write your \s-1CGI\s0 programs, so investigate them with |
| 767 | care. |
| 768 | .PP |
| 769 | See http://www.cpan.org/modules/by\-category/15_World_Wide_Web_HTML_HTTP_CGI/ . |
| 770 | .PP |
| 771 | A non\-free, commercial product, ``The Velocity Engine for Perl'', |
| 772 | (http://www.binevolve.com/ or http://www.binevolve.com/velocigen/ ) |
| 773 | might also be worth looking at. It will allow you to increase the |
| 774 | performance of your Perl programs, running programs up to 25 times |
| 775 | faster than normal \s-1CGI\s0 Perl when running in persistent Perl mode or 4 |
| 776 | to 5 times faster without any modification to your existing \s-1CGI\s0 |
| 777 | programs. Fully functional evaluation copies are available from the |
| 778 | web site. |
| 779 | .Sh "How can I hide the source for my Perl program?" |
| 780 | .IX Subsection "How can I hide the source for my Perl program?" |
| 781 | Delete it. :\-) Seriously, there are a number of (mostly |
| 782 | unsatisfactory) solutions with varying levels of ``security''. |
| 783 | .PP |
| 784 | First of all, however, you \fIcan't\fR take away read permission, because |
| 785 | the source code has to be readable in order to be compiled and |
| 786 | interpreted. (That doesn't mean that a \s-1CGI\s0 script's source is |
| 787 | readable by people on the web, though\*(--only by people with access to |
| 788 | the filesystem.) So you have to leave the permissions at the socially |
| 789 | friendly 0755 level. |
| 790 | .PP |
| 791 | Some people regard this as a security problem. If your program does |
| 792 | insecure things and relies on people not knowing how to exploit those |
| 793 | insecurities, it is not secure. It is often possible for someone to |
| 794 | determine the insecure things and exploit them without viewing the |
| 795 | source. Security through obscurity, the name for hiding your bugs |
| 796 | instead of fixing them, is little security indeed. |
| 797 | .PP |
| 798 | You can try using encryption via source filters (Starting from Perl |
| 799 | 5.8 the Filter::Simple and Filter::Util::Call modules are included in |
| 800 | the standard distribution), but any decent programmer will be able to |
| 801 | decrypt it. You can try using the byte code compiler and interpreter |
| 802 | described below, but the curious might still be able to de-compile it. |
| 803 | You can try using the native-code compiler described below, but |
| 804 | crackers might be able to disassemble it. These pose varying degrees |
| 805 | of difficulty to people wanting to get at your code, but none can |
| 806 | definitively conceal it (true of every language, not just Perl). |
| 807 | .PP |
| 808 | If you're concerned about people profiting from your code, then the |
| 809 | bottom line is that nothing but a restrictive license will give you |
| 810 | legal security. License your software and pepper it with threatening |
| 811 | statements like ``This is unpublished proprietary software of \s-1XYZ\s0 Corp. |
| 812 | Your access to it does not give you permission to use it blah blah |
| 813 | blah.'' We are not lawyers, of course, so you should see a lawyer if |
| 814 | you want to be sure your license's wording will stand up in court. |
| 815 | .Sh "How can I compile my Perl program into byte code or C?" |
| 816 | .IX Subsection "How can I compile my Perl program into byte code or C?" |
| 817 | Malcolm Beattie has written a multifunction backend compiler, |
| 818 | available from \s-1CPAN\s0, that can do both these things. It is included |
| 819 | in the perl5.005 release, but is still considered experimental. |
| 820 | This means it's fun to play with if you're a programmer but not |
| 821 | really for people looking for turn-key solutions. |
| 822 | .PP |
| 823 | Merely compiling into C does not in and of itself guarantee that your |
| 824 | code will run very much faster. That's because except for lucky cases |
| 825 | where a lot of native type inferencing is possible, the normal Perl |
| 826 | run-time system is still present and so your program will take just as |
| 827 | long to run and be just as big. Most programs save little more than |
| 828 | compilation time, leaving execution no more than 10\-30% faster. A few |
| 829 | rare programs actually benefit significantly (even running several times |
| 830 | faster), but this takes some tweaking of your code. |
| 831 | .PP |
| 832 | You'll probably be astonished to learn that the current version of the |
| 833 | compiler generates a compiled form of your script whose executable is |
| 834 | just as big as the original perl executable, and then some. That's |
| 835 | because as currently written, all programs are prepared for a full |
| 836 | \&\fIeval()\fR statement. You can tremendously reduce this cost by building a |
| 837 | shared \fIlibperl.so\fR library and linking against that. See the |
| 838 | \&\fI\s-1INSTALL\s0\fR podfile in the Perl source distribution for details. If |
| 839 | you link your main perl binary with this, it will make it minuscule. |
| 840 | For example, on one author's system, \fI/usr/bin/perl\fR is only 11k in |
| 841 | size! |
| 842 | .PP |
| 843 | In general, the compiler will do nothing to make a Perl program smaller, |
| 844 | faster, more portable, or more secure. In fact, it can make your |
| 845 | situation worse. The executable will be bigger, your \s-1VM\s0 system may take |
| 846 | longer to load the whole thing, the binary is fragile and hard to fix, |
| 847 | and compilation never stopped software piracy in the form of crackers, |
| 848 | viruses, or bootleggers. The real advantage of the compiler is merely |
| 849 | packaging, and once you see the size of what it makes (well, unless |
| 850 | you use a shared \fIlibperl.so\fR), you'll probably want a complete |
| 851 | Perl install anyway. |
| 852 | .Sh "How can I compile Perl into Java?" |
| 853 | .IX Subsection "How can I compile Perl into Java?" |
| 854 | You can also integrate Java and Perl with the |
| 855 | Perl Resource Kit from O'Reilly and Associates. See |
| 856 | http://www.oreilly.com/catalog/prkunix/ . |
| 857 | .PP |
| 858 | Perl 5.6 comes with Java Perl Lingo, or \s-1JPL\s0. \s-1JPL\s0, still in |
| 859 | development, allows Perl code to be called from Java. See jpl/README |
| 860 | in the Perl source tree. |
| 861 | .ie n .Sh "How can I get ""#!perl"" to work on [\s-1MS\-DOS\s0,NT,...]?" |
| 862 | .el .Sh "How can I get \f(CW#!perl\fP to work on [\s-1MS\-DOS\s0,NT,...]?" |
| 863 | .IX Subsection "How can I get #!perl to work on [MS-DOS,NT,...]?" |
| 864 | For \s-1OS/2\s0 just use |
| 865 | .PP |
| 866 | .Vb 1 |
| 867 | \& extproc perl -S -your_switches |
| 868 | .Ve |
| 869 | .PP |
| 870 | as the first line in \f(CW\*(C`*.cmd\*(C'\fR file (\f(CW\*(C`\-S\*(C'\fR due to a bug in cmd.exe's |
| 871 | `extproc' handling). For \s-1DOS\s0 one should first invent a corresponding |
| 872 | batch file and codify it in \f(CW\*(C`ALTERNATIVE_SHEBANG\*(C'\fR (see the |
| 873 | \&\fI\s-1INSTALL\s0\fR file in the source distribution for more information). |
| 874 | .PP |
| 875 | The Win95/NT installation, when using the ActiveState port of Perl, |
| 876 | will modify the Registry to associate the \f(CW\*(C`.pl\*(C'\fR extension with the |
| 877 | perl interpreter. If you install another port, perhaps even building |
| 878 | your own Win95/NT Perl from the standard sources by using a Windows port |
| 879 | of gcc (e.g., with cygwin or mingw32), then you'll have to modify |
| 880 | the Registry yourself. In addition to associating \f(CW\*(C`.pl\*(C'\fR with the |
| 881 | interpreter, \s-1NT\s0 people can use: \f(CW\*(C`SET PATHEXT=%PATHEXT%;.PL\*(C'\fR to let them |
| 882 | run the program \f(CW\*(C`install\-linux.pl\*(C'\fR merely by typing \f(CW\*(C`install\-linux\*(C'\fR. |
| 883 | .PP |
| 884 | Macintosh Perl programs will have the appropriate Creator and |
| 885 | Type, so that double-clicking them will invoke the Perl application. |
| 886 | .PP |
| 887 | \&\fI\s-1IMPORTANT\s0!\fR: Whatever you do, \s-1PLEASE\s0 don't get frustrated, and just |
| 888 | throw the perl interpreter into your cgi-bin directory, in order to |
| 889 | get your programs working for a web server. This is an \s-1EXTREMELY\s0 big |
| 890 | security risk. Take the time to figure out how to do it correctly. |
| 891 | .Sh "Can I write useful Perl programs on the command line?" |
| 892 | .IX Subsection "Can I write useful Perl programs on the command line?" |
| 893 | Yes. Read perlrun for more information. Some examples follow. |
| 894 | (These assume standard Unix shell quoting rules.) |
| 895 | .PP |
| 896 | .Vb 2 |
| 897 | \& # sum first and last fields |
| 898 | \& perl -lane 'print $F[0] + $F[-1]' * |
| 899 | .Ve |
| 900 | .PP |
| 901 | .Vb 2 |
| 902 | \& # identify text files |
| 903 | \& perl -le 'for(@ARGV) {print if -f && -T _}' * |
| 904 | .Ve |
| 905 | .PP |
| 906 | .Vb 2 |
| 907 | \& # remove (most) comments from C program |
| 908 | \& perl -0777 -pe 's{/\e*.*?\e*/}{}gs' foo.c |
| 909 | .Ve |
| 910 | .PP |
| 911 | .Vb 2 |
| 912 | \& # make file a month younger than today, defeating reaper daemons |
| 913 | \& perl -e '$X=24*60*60; utime(time(),time() + 30 * $X,@ARGV)' * |
| 914 | .Ve |
| 915 | .PP |
| 916 | .Vb 2 |
| 917 | \& # find first unused uid |
| 918 | \& perl -le '$i++ while getpwuid($i); print $i' |
| 919 | .Ve |
| 920 | .PP |
| 921 | .Vb 3 |
| 922 | \& # display reasonable manpath |
| 923 | \& echo $PATH | perl -nl -072 -e ' |
| 924 | \& s![^/+]*$!man!&&-d&&!$s{$_}++&&push@m,$_;END{print"@m"}' |
| 925 | .Ve |
| 926 | .PP |
| 927 | \&\s-1OK\s0, the last one was actually an Obfuscated Perl Contest entry. :\-) |
| 928 | .Sh "Why don't Perl one-liners work on my DOS/Mac/VMS system?" |
| 929 | .IX Subsection "Why don't Perl one-liners work on my DOS/Mac/VMS system?" |
| 930 | The problem is usually that the command interpreters on those systems |
| 931 | have rather different ideas about quoting than the Unix shells under |
| 932 | which the one-liners were created. On some systems, you may have to |
| 933 | change single-quotes to double ones, which you must \fI\s-1NOT\s0\fR do on Unix |
| 934 | or Plan9 systems. You might also have to change a single % to a %%. |
| 935 | .PP |
| 936 | For example: |
| 937 | .PP |
| 938 | .Vb 2 |
| 939 | \& # Unix |
| 940 | \& perl -e 'print "Hello world\en"' |
| 941 | .Ve |
| 942 | .PP |
| 943 | .Vb 2 |
| 944 | \& # DOS, etc. |
| 945 | \& perl -e "print \e"Hello world\en\e"" |
| 946 | .Ve |
| 947 | .PP |
| 948 | .Vb 3 |
| 949 | \& # Mac |
| 950 | \& print "Hello world\en" |
| 951 | \& (then Run "Myscript" or Shift-Command-R) |
| 952 | .Ve |
| 953 | .PP |
| 954 | .Vb 2 |
| 955 | \& # MPW |
| 956 | \& perl -e 'print "Hello world\en"' |
| 957 | .Ve |
| 958 | .PP |
| 959 | .Vb 2 |
| 960 | \& # VMS |
| 961 | \& perl -e "print ""Hello world\en""" |
| 962 | .Ve |
| 963 | .PP |
| 964 | The problem is that none of these examples are reliable: they depend on the |
| 965 | command interpreter. Under Unix, the first two often work. Under \s-1DOS\s0, |
| 966 | it's entirely possible that neither works. If 4DOS was the command shell, |
| 967 | you'd probably have better luck like this: |
| 968 | .PP |
| 969 | .Vb 1 |
| 970 | \& perl -e "print <Ctrl-x>"Hello world\en<Ctrl-x>"" |
| 971 | .Ve |
| 972 | .PP |
| 973 | Under the Mac, it depends which environment you are using. The MacPerl |
| 974 | shell, or \s-1MPW\s0, is much like Unix shells in its support for several |
| 975 | quoting variants, except that it makes free use of the Mac's non-ASCII |
| 976 | characters as control characters. |
| 977 | .PP |
| 978 | Using \fIqq()\fR, q(), and \fIqx()\fR, instead of \*(L"double quotes\*(R", 'single |
| 979 | quotes', and `backticks`, may make one-liners easier to write. |
| 980 | .PP |
| 981 | There is no general solution to all of this. It is a mess. |
| 982 | .PP |
| 983 | [Some of this answer was contributed by Kenneth Albanowski.] |
| 984 | .Sh "Where can I learn about \s-1CGI\s0 or Web programming in Perl?" |
| 985 | .IX Subsection "Where can I learn about CGI or Web programming in Perl?" |
| 986 | For modules, get the \s-1CGI\s0 or \s-1LWP\s0 modules from \s-1CPAN\s0. For textbooks, |
| 987 | see the two especially dedicated to web stuff in the question on |
| 988 | books. For problems and questions related to the web, like ``Why |
| 989 | do I get 500 Errors'' or ``Why doesn't it run from the browser right |
| 990 | when it runs fine on the command line'', see the troubleshooting |
| 991 | guides and references in perlfaq9 or in the \s-1CGI\s0 MetaFAQ: |
| 992 | .PP |
| 993 | .Vb 1 |
| 994 | \& http://www.perl.org/CGI_MetaFAQ.html |
| 995 | .Ve |
| 996 | .Sh "Where can I learn about object-oriented Perl programming?" |
| 997 | .IX Subsection "Where can I learn about object-oriented Perl programming?" |
| 998 | A good place to start is perltoot, and you can use perlobj, |
| 999 | perlboot, perltoot, perltooc, and perlbot for reference. |
| 1000 | (If you are using really old Perl, you may not have all of these, |
| 1001 | try http://www.perldoc.com/ , but consider upgrading your perl.) |
| 1002 | .PP |
| 1003 | A good book on \s-1OO\s0 on Perl is the \*(L"Object\-Oriented Perl\*(R" |
| 1004 | by Damian Conway from Manning Publications, |
| 1005 | http://www.manning.com/Conway/index.html |
| 1006 | .Sh "Where can I learn about linking C with Perl? [h2xs, xsubpp]" |
| 1007 | .IX Subsection "Where can I learn about linking C with Perl? [h2xs, xsubpp]" |
| 1008 | If you want to call C from Perl, start with perlxstut, |
| 1009 | moving on to perlxs, xsubpp, and perlguts. If you want to |
| 1010 | call Perl from C, then read perlembed, perlcall, and |
| 1011 | perlguts. Don't forget that you can learn a lot from looking at |
| 1012 | how the authors of existing extension modules wrote their code and |
| 1013 | solved their problems. |
| 1014 | .Sh "I've read perlembed, perlguts, etc., but I can't embed perl in my C program; what am I doing wrong?" |
| 1015 | .IX Subsection "I've read perlembed, perlguts, etc., but I can't embed perl in my C program; what am I doing wrong?" |
| 1016 | Download the ExtUtils::Embed kit from \s-1CPAN\s0 and run `make test'. If |
| 1017 | the tests pass, read the pods again and again and again. If they |
| 1018 | fail, see perlbug and send a bug report with the output of |
| 1019 | \&\f(CW\*(C`make test TEST_VERBOSE=1\*(C'\fR along with \f(CW\*(C`perl \-V\*(C'\fR. |
| 1020 | .Sh "When I tried to run my script, I got this message. What does it mean?" |
| 1021 | .IX Subsection "When I tried to run my script, I got this message. What does it mean?" |
| 1022 | A complete list of Perl's error messages and warnings with explanatory |
| 1023 | text can be found in perldiag. You can also use the splain program |
| 1024 | (distributed with Perl) to explain the error messages: |
| 1025 | .PP |
| 1026 | .Vb 2 |
| 1027 | \& perl program 2>diag.out |
| 1028 | \& splain [-v] [-p] diag.out |
| 1029 | .Ve |
| 1030 | .PP |
| 1031 | or change your program to explain the messages for you: |
| 1032 | .PP |
| 1033 | .Vb 1 |
| 1034 | \& use diagnostics; |
| 1035 | .Ve |
| 1036 | .PP |
| 1037 | or |
| 1038 | .PP |
| 1039 | .Vb 1 |
| 1040 | \& use diagnostics -verbose; |
| 1041 | .Ve |
| 1042 | .Sh "What's MakeMaker?" |
| 1043 | .IX Subsection "What's MakeMaker?" |
| 1044 | This module (part of the standard Perl distribution) is designed to |
| 1045 | write a Makefile for an extension module from a Makefile.PL. For more |
| 1046 | information, see ExtUtils::MakeMaker. |
| 1047 | .SH "AUTHOR AND COPYRIGHT" |
| 1048 | .IX Header "AUTHOR AND COPYRIGHT" |
| 1049 | Copyright (c) 1997\-2002 Tom Christiansen and Nathan Torkington. |
| 1050 | All rights reserved. |
| 1051 | .PP |
| 1052 | This documentation is free; you can redistribute it and/or modify it |
| 1053 | under the same terms as Perl itself. |
| 1054 | .PP |
| 1055 | Irrespective of its distribution, all code examples here are in the public |
| 1056 | domain. You are permitted and encouraged to use this code and any |
| 1057 | derivatives thereof in your own programs for fun or for profit as you |
| 1058 | see fit. A simple comment in the code giving credit to the \s-1FAQ\s0 would |
| 1059 | be courteous but is not required. |