⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 perlrun.pod

📁 MSYS在windows下模拟了一个类unix的终端
💻 POD
📖 第 1 页 / 共 3 页
字号:
runs the program under the control of a debugging, profiling, ortracing module installed as Devel::foo. E.g., B<-d:DProf> executesthe program using the Devel::DProf profiler.  As with the B<-M>flag, options may be passed to the Devel::foo package where theywill be received and interpreted by the Devel::foo::import routine.The comma-separated list of options must follow a C<=> character.See L<perldebug>.=item B<-D>I<letters>=item B<-D>I<number>sets debugging flags.  To watch how it executes your program, useB<-Dtls>.  (This works only if debugging is compiled into yourPerl.)  Another nice value is B<-Dx>, which lists your compiledsyntax tree.  And B<-Dr> displays compiled regular expressions. As analternative, specify a number instead of list of letters (e.g., B<-D14> isequivalent to B<-Dtls>):        1  p  Tokenizing and parsing        2  s  Stack snapshots        4  l  Context (loop) stack processing        8  t  Trace execution       16  o  Method and overloading resolution       32  c  String/numeric conversions       64  P  Print preprocessor command for -P, source file input state      128  m  Memory allocation      256  f  Format processing      512  r  Regular expression parsing and execution     1024  x  Syntax tree dump     2048  u  Tainting checks     4096  L  Memory leaks (needs -DLEAKTEST when compiling Perl)     8192  H  Hash dump -- usurps values()    16384  X  Scratchpad allocation    32768  D  Cleaning up    65536  S  Thread synchronization   131072  T  TokenisingAll these flags require B<-DDEBUGGING> when you compile the Perlexecutable.  See the F<INSTALL> file in the Perl source distribution for how to do this.  This flag is automatically set if you include B<-g>option when C<Configure> asks you about optimizer/debugger flags.If you're just trying to get a print out of each line of Perl codeas it executes, the way that C<sh -x> provides for shell scripts,you can't use Perl's B<-D> switch.  Instead do this   # Bourne shell syntax  $ PERLDB_OPTS="NonStop=1 AutoTrace=1 frame=2" perl -dS program  # csh syntax  % (setenv PERLDB_OPTS "NonStop=1 AutoTrace=1 frame=2"; perl -dS program)See L<perldebug> for details and variations.=item B<-e> I<commandline>may be used to enter one line of program.  If B<-e> is given, Perlwill not look for a filename in the argument list.  Multiple B<-e>commands may be given to build up a multi-line script.  Make sureto use semicolons where you would in a normal program.=item B<-F>I<pattern>specifies the pattern to split on if B<-a> is also in effect.  Thepattern may be surrounded by C<//>, C<"">, or C<''>, otherwise it will beput in single quotes.=item B<-h>prints a summary of the options.=item B<-i>[I<extension>]specifies that files processed by the C<E<lt>E<gt>> construct are to beedited in-place.  It does this by renaming the input file, opening theoutput file by the original name, and selecting that output file as thedefault for print() statements.  The extension, if supplied, is used tomodify the name of the old file to make a backup copy, following theserules:If no extension is supplied, no backup is made and the current file isoverwritten.If the extension doesn't contain a C<*>, then it is appended to theend of the current filename as a suffix.  If the extension doescontain one or more C<*> characters, then each C<*> is replacedwith the current filename.  In Perl terms, you could think of thisas:    ($backup = $extension) =~ s/\*/$file_name/g;This allows you to add a prefix to the backup file, instead of (or inaddition to) a suffix:    $ perl -pi 'orig_*' -e 's/bar/baz/' fileA	# backup to 'orig_fileA'Or even to place backup copies of the original files into anotherdirectory (provided the directory already exists):    $ perl -pi 'old/*.orig' -e 's/bar/baz/' fileA # backup to 'old/fileA.orig'These sets of one-liners are equivalent:    $ perl -pi -e 's/bar/baz/' fileA		# overwrite current file    $ perl -pi '*' -e 's/bar/baz/' fileA	# overwrite current file    $ perl -pi '.orig' -e 's/bar/baz/' fileA	# backup to 'fileA.orig'    $ perl -pi '*.orig' -e 's/bar/baz/' fileA	# backup to 'fileA.orig'From the shell, saying    $ perl -p -i.orig -e "s/foo/bar/; ... "is the same as using the program:    #!/usr/bin/perl -pi.orig    s/foo/bar/;which is equivalent to    #!/usr/bin/perl    $extension = '.orig';    LINE: while (<>) {	if ($ARGV ne $oldargv) {	    if ($extension !~ /\*/) {		$backup = $ARGV . $extension;	    }	    else {		($backup = $extension) =~ s/\*/$ARGV/g;	    }	    rename($ARGV, $backup);	    open(ARGVOUT, ">$ARGV");	    select(ARGVOUT);	    $oldargv = $ARGV;	}	s/foo/bar/;    }    continue {	print;	# this prints to original filename    }    select(STDOUT);except that the B<-i> form doesn't need to compare $ARGV to $oldargv toknow when the filename has changed.  It does, however, use ARGVOUT forthe selected filehandle.  Note that STDOUT is restored as the defaultoutput filehandle after the loop.As shown above, Perl creates the backup file whether or not any outputis actually changed.  So this is just a fancy way to copy files:    $ perl -p -i '/some/file/path/*' -e 1 file1 file2 file3...or    $ perl -p -i '.orig' -e 1 file1 file2 file3...You can use C<eof> without parentheses to locate the end of each inputfile, in case you want to append to each file, or reset line numbering(see example in L<perlfunc/eof>).If, for a given file, Perl is unable to create the backup file asspecified in the extension then it will skip that file and continue onwith the next one (if it exists).For a discussion of issues surrounding file permissions and B<-i>,see L<perlfaq5/Why does Perl let me delete read-only files?  Why does -i clobber protected files?  Isn't this a bug in Perl?>.You cannot use B<-i> to create directories or to strip extensions fromfiles.Perl does not expand C<~> in filenames, which is good, since somefolks use it for their backup files:    $ perl -pi~ -e 's/foo/bar/' file1 file2 file3...Finally, the B<-i> switch does not impede execution when nofiles are given on the command line.  In this case, no backup is made(the original file cannot, of course, be determined) and processingproceeds from STDIN to STDOUT as might be expected.=item B<-I>I<directory>Directories specified by B<-I> are prepended to the search path formodules (C<@INC>), and also tells the C preprocessor where to search forinclude files.  The C preprocessor is invoked with B<-P>; by default itsearches /usr/include and /usr/lib/perl.=item B<-l>[I<octnum>]enables automatic line-ending processing.  It has two separateeffects.  First, it automatically chomps C<$/> (the input recordseparator) when used with B<-n> or B<-p>.  Second, it assigns C<$\>(the output record separator) to have the value of I<octnum> sothat any print statements will have that separator added back on.If I<octnum> is omitted, sets C<$\> to the current value ofC<$/>.  For instance, to trim lines to 80 columns:    perl -lpe 'substr($_, 80) = ""'Note that the assignment C<$\ = $/> is done when the switch is processed,so the input record separator can be different than the output recordseparator if the B<-l> switch is followed by a B<-0> switch:    gnufind / -print0 | perl -ln0e 'print "found $_" if -p'This sets C<$\> to newline and then sets C<$/> to the null character.=item B<-m>[B<->]I<module>=item B<-M>[B<->]I<module>=item B<-M>[B<->]I<'module ...'>=item B<-[mM]>[B<->]I<module=arg[,arg]...>B<-m>I<module> executes C<use> I<module> C<();> before executing yourprogram.B<-M>I<module> executes C<use> I<module> C<;> before executing yourprogram.  You can use quotes to add extra code after the module name,e.g., C<'-Mmodule qw(foo bar)'>.If the first character after the B<-M> or B<-m> is a dash (C<->)then the 'use' is replaced with 'no'.A little builtin syntactic sugar means you can also sayB<-mmodule=foo,bar> or B<-Mmodule=foo,bar> as a shortcut forC<'-Mmodule qw(foo bar)'>.  This avoids the need to use quotes whenimporting symbols.  The actual code generated by B<-Mmodule=foo,bar> isC<use module split(/,/,q{foo,bar})>.  Note that the C<=> formremoves the distinction between B<-m> and B<-M>.=item B<-n>causes Perl to assume the following loop around your program, whichmakes it iterate over filename arguments somewhat like B<sed -n> orB<awk>:  LINE:    while (<>) {	...		# your program goes here    }Note that the lines are not printed by default.  See B<-p> to havelines printed.  If a file named by an argument cannot be opened forsome reason, Perl warns you about it and moves on to the next file.Here is an efficient way to delete all files older than a week:    find . -mtime +7 -print | perl -nle unlinkThis is faster than using the B<-exec> switch of B<find> because you don'thave to start a process on every filename found.  It does suffer fromthe bug of mishandling newlines in pathnames, which you can fix ifyouC<BEGIN> and C<END> blocks may be used to capture control before or afterthe implicit program loop, just as in B<awk>.=item B<-p>causes Perl to assume the following loop around your program, whichmakes it iterate over filename arguments somewhat like B<sed>:  LINE:    while (<>) {	...		# your program goes here    } continue {	print or die "-p destination: $!\n";    }If a file named by an argument cannot be opened for some reason, Perlwarns you about it, and moves on to the next file.  Note that thelines are printed automatically.  An error occurring during printing istreated as fatal.  To suppress printing use the B<-n> switch.  A B<-p>overrides a B<-n> switch.C<BEGIN> and C<END> blocks may be used to capture control before or afterthe implicit loop, just as in B<awk>.=item B<-P>causes your program to be run through the C preprocessor beforecompilation by Perl.  Because both comments and B<cpp> directives beginwith the # character, you should avoid starting comments with any wordsrecognized by the C preprocessor such as C<"if">, C<"else">, or C<"define">.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -