📄 perlwin32.pod
字号:
quoting rules are implemented, but here are some general observationsbased on experiments: The C runtime breaks arguments at spaces andpasses them to programs in argc/argv. Double quotes can be used toprevent arguments with spaces in them from being split up. You canput a double quote in an argument by escaping it with a backslash andenclosing the whole argument within double quotes. The backslash andthe pair of double quotes surrounding the argument will be stripped bythe C runtime.The file redirection characters "<", ">", and "|" can be quoted bydouble quotes (although there are suggestions that this may not alwaysbe true). Single quotes are not treated as quotes by the shell orthe C runtime, they don't get stripped by the shell (just to makethis type of quoting completely useless). The caret "^" has alsobeen observed to behave as a quoting character, but this appearsto be a shell feature, and the caret is not stripped from the commandline, so Perl still sees it (and the C runtime phase does not treatthe caret as a quote character).Here are some examples of usage of the "cmd" shell:This prints two doublequotes: perl -e "print '\"\"' "This does the same: perl -e "print \"\\\"\\\"\" "This prints "bar" and writes "foo" to the file "blurch": perl -e "print 'foo'; print STDERR 'bar'" > blurchThis prints "foo" ("bar" disappears into nowhereland): perl -e "print 'foo'; print STDERR 'bar'" 2> nulThis prints "bar" and writes "foo" into the file "blurch": perl -e "print 'foo'; print STDERR 'bar'" 1> blurchThis pipes "foo" to the "less" pager and prints "bar" on the console: perl -e "print 'foo'; print STDERR 'bar'" | lessThis pipes "foo\nbar\n" to the less pager: perl -le "print 'foo'; print STDERR 'bar'" 2>&1 | lessThis pipes "foo" to the pager and writes "bar" in the file "blurch": perl -e "print 'foo'; print STDERR 'bar'" 2> blurch | lessDiscovering the usefulness of the "command.com" shell on Windows 9xis left as an exercise to the reader :)One particularly pernicious problem with the 4NT command shell forWindows NT is that it (nearly) always treats a % character as indicatingthat environment variable expansion is needed. Under this shell, it istherefore important to always double any % characters which you wantPerl to see (for example, for hash variables), even when they arequoted.=item Building ExtensionsThe Comprehensive Perl Archive Network (CPAN) offers a wealthof extensions, some of which require a C compiler to build.Look in http://www.cpan.org/ for more information on CPAN.Note that not all of the extensions available from CPAN may workin the Win32 environment; you should check the information athttp://testers.cpan.org/ before investing too much effort intoporting modules that don't readily build.Most extensions (whether they require a C compiler or not) canbe built, tested and installed with the standard mantra: perl Makefile.PL $MAKE $MAKE test $MAKE installwhere $MAKE is whatever 'make' program you have configured perl touse. Use "perl -V:make" to find out what this is. Some extensionsmay not provide a testsuite (so "$MAKE test" may not do anything orfail), but most serious ones do.It is important that you use a supported 'make' program, andensure Config.pm knows about it. If you don't have nmake, you caneither get dmake from the location mentioned earlier or get anold version of nmake reportedly available from: ftp://ftp.microsoft.com/Softlib/MSLFILES/nmake15.exeAnother option is to use the make written in Perl, available fromCPAN: http://www.cpan.org/authors/id/NI-S/Make-0.03.tar.gzYou may also use dmake. See L</"Make"> above on how to get it.Note that MakeMaker actually emits makefiles with different syntaxdepending on what 'make' it thinks you are using. Therefore, it isimportant that one of the following values appears in Config.pm: make='nmake' # MakeMaker emits nmake syntax make='dmake' # MakeMaker emits dmake syntax any other value # MakeMaker emits generic make syntax (e.g GNU make, or Perl make)If the value doesn't match the 'make' program you want to use,edit Config.pm to fix it.If a module implements XSUBs, you will need one of the supportedC compilers. You must make sure you have set up the environment forthe compiler for command-line compilation.If a module does not build for some reason, look carefully forwhy it failed, and report problems to the module author. Ifit looks like the extension building support is at fault, reportthat with full details of how the build failed using the perlbugutility.=item Command-line Wildcard ExpansionThe default command shells on DOS descendant operating systems (suchas they are) usually do not expand wildcard arguments supplied toprograms. They consider it the application's job to handle that.This is commonly achieved by linking the application (in our case,perl) with startup code that the C runtime libraries usually provide.However, doing that results in incompatible perl versions (since thebehavior of the argv expansion code differs depending on thecompiler, and it is even buggy on some compilers). Besides, it maybe a source of frustration if you use such a perl binary with analternate shell that *does* expand wildcards.Instead, the following solution works rather well. The nice thingsabout it are 1) you can start using it right away; 2) it is more powerful, because it will do the right thing with a pattern like*/*/*.c; 3) you can decide whether you do/don't want to use it; and4) you can extend the method to add any customizations (or even entirely different kinds of wildcard expansion). C:\> copy con c:\perl\lib\Wild.pm # Wild.pm - emulate shell @ARGV expansion on shells that don't use File::DosGlob; @ARGV = map { my @g = File::DosGlob::glob($_) if /[*?]/; @g ? @g : $_; } @ARGV; 1; ^Z C:\> set PERL5OPT=-MWild C:\> perl -le "for (@ARGV) { print }" */*/perl*.c p4view/perl/perl.c p4view/perl/perlio.c p4view/perl/perly.c perl5.005/win32/perlglob.c perl5.005/win32/perllib.c perl5.005/win32/perlglob.c perl5.005/win32/perllib.c perl5.005/win32/perlglob.c perl5.005/win32/perllib.cNote there are two distinct steps there: 1) You'll have to createWild.pm and put it in your perl lib directory. 2) You'll need toset the PERL5OPT environment variable. If you want argv expansionto be the default, just set PERL5OPT in your default startupenvironment.If you are using the Visual C compiler, you can get the C runtime'scommand line wildcard expansion built into perl binary. The resultingbinary will always expand unquoted command lines, which may not bewhat you want if you use a shell that does that for you. The expansiondone is also somewhat less powerful than the approach suggested above.=item Win32 Specific ExtensionsA number of extensions specific to the Win32 platform are availablefrom CPAN. You may find that many of these extensions are meant tobe used under the Activeware port of Perl, which used to be the onlynative port for the Win32 platform. Since the Activeware port does nothave adequate support for Perl's extension building tools, theseextensions typically do not support those tools either and, therefore,cannot be built using the generic steps shown in the previous section.To ensure smooth transitioning of existing code that uses theActiveState port, there is a bundle of Win32 extensions that containsall of the ActiveState extensions and most other Win32 extensions fromCPAN in source form, along with many added bugfixes, and with MakeMakersupport. This bundle is available at: http://www.cpan.org/authors/id/GSAR/libwin32-0.151.zipSee the README in that distribution for building and installationinstructions. Look for later versions that may be available at thesame location.=item Running Perl ScriptsPerl scripts on UNIX use the "#!" (a.k.a "shebang") line toindicate to the OS that it should execute the file using perl.Win32 has no comparable means to indicate arbitrary files areexecutables.Instead, all available methods to execute plain text files onWin32 rely on the file "extension". There are three methodsto use this to execute perl scripts:=over 8=item 1There is a facility called "file extension associations" that willwork in Windows NT 4.0. This can be manipulated via the twocommands "assoc" and "ftype" that come standard with Windows NT4.0. Type "ftype /?" for a complete example of how to set thisup for perl scripts (Say what? You thought Windows NT wasn'tperl-ready? :).=item 2Since file associations don't work everywhere, and there arereportedly bugs with file associations where it does work, theold method of wrapping the perl script to make it look like aregular batch file to the OS, may be used. The install processmakes available the "pl2bat.bat" script which can be used to wrapperl scripts into batch files. For example: pl2bat foo.plwill create the file "FOO.BAT". Note "pl2bat" strips any.pl suffix and adds a .bat suffix to the generated file.If you use the 4DOS/NT or similar command shell, note that"pl2bat" uses the "%*" variable in the generated batch file torefer to all the command line arguments, so you may need to makesure that construct works in batch files. As of this writing,4DOS/NT users will need a "ParameterChar = *" statement in their4NT.INI file or will need to execute "setdos /p*" in the 4DOS/NTstartup file to enable this to work.=item 3Using "pl2bat" has a few problems: the file name gets changed,so scripts that rely on C<$0> to find what they must do may notrun properly; running "pl2bat" replicates the contents of theoriginal script, and so this process can be maintenance intensiveif the originals get updated often. A different approach thatavoids both problems is possible.A script called "runperl.bat" is available that can be copiedto any filename (along with the .bat suffix). For example,if you call it "foo.bat", it will run the file "foo" when it isexecuted. Since you can run batch files on Win32 platforms simplyby typing the name (without the extension), this effectivelyruns the file "foo", when you type either "foo" or "foo.bat".With this method, "foo.bat" can even be in a different locationthan the file "foo", as long as "foo" is available somewhere onthe PATH. If your scripts are on a filesystem that allows symboliclinks, you can even avoid copying "runperl.bat".Here's a diversion: copy "runperl.bat" to "runperl", and type"runperl". Explain the observed behavior, or lack thereof. :)Hint: .gnidnats llits er'uoy fi ,"lrepnur" eteled :tniH=back=item Miscellaneous ThingsA full set of HTML documentation is installed, so you should beable to use it if you have a web browser installed on yoursystem.C<perldoc> is also a useful tool for browsing information containedin the documentation, especially in conjunction with a pagerlike C<less> (recent versions of which have Win32 support). You mayhave to set the PAGER environment variable to use a specific pager."perldoc -f foo" will print information about the perl operator"foo".If you find bugs in perl, you can run C<perlbug> to create abug report (you may have to send it manually if C<perlbug> cannotfind a mailer on your system).=back=head1 BUGS AND CAVEATSSome of the built-in functions do not act exactly as documented inL<perlfunc>, and a few are not implemented at all. To avoidsurprises, particularly if you have had prior exposure to Perlin other operating environments or if you intend to write codethat will be portable to other environments. See L<perlport>for a reasonably definitive list of these differences.Not all extensions available from CPAN may build or work properlyin the Win32 environment. See L</"Building Extensions">.Most C<socket()> related calls are supported, but they may notbehave as on Unix platforms. See L<perlport> for the full list.Signal handling may not behave as on Unix platforms (where itdoesn't exactly "behave", either :). For instance, calling C<die()>or C<exit()> from signal handlers will cause an exception, since mostimplementations of C<signal()> on Win32 are severely crippled.Thus, signals may work only for simple things like setting a flagvariable in the handler. Using signals under this port shouldcurrently be considered unsupported.Please send detailed descriptions of any problems and solutions that you may find to <F<perlbug@perl.com>>, along with the output producedby C<perl -V>.=head1 AUTHORS=over 4=item Gary Ng E<lt>71564.1743@CompuServe.COME<gt>=item Gurusamy Sarathy E<lt>gsar@activestate.comE<gt>=item Nick Ing-Simmons E<lt>nick@ni-s.u-net.comE<gt>=backThis document is maintained by Gurusamy Sarathy.=head1 SEE ALSOL<perl>=head1 HISTORYThis port was originally contributed by Gary Ng around 5.003_24,and borrowed from the Hip Communications port that was availableat the time. Various people have made numerous and sundry hackssince then.Borland support was added in 5.004_01 (Gurusamy Sarathy).GCC/mingw32 support was added in 5.005 (Nick Ing-Simmons).Support for PERL_OBJECT was added in 5.005 (ActiveState Tool Corp).Support for fork() emulation was added in 5.6 (ActiveState Tool Corp).Win9x support was added in 5.6 (Benjamin Stuhl).Last updated: 1 April 2001=cut
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -