Command Line Options


Beginning | Previous | Next

Running an Interactive Debug Session

To run an interactive session in Perl type the following at the command prompt: % perl -de 0 You will get a screen that looks something like: d:/home/khamsi> perl -de 0 Loading DB routines from $RCSfile: CmdLineOptions.html,v $$Revision: 1.2 $$Date: 92/08/07 18:24:07 $ Emacs support available. Enter h for help. main::(-e:1): 0 DB<1> From the DB<n> prompt, you will be able to type just about any valid Perl command. Multiple line commands can be continued on the next line by ending the line with a backslash "\". Use this to test everything before having to write a script.

Turning On Warnings

The "-w" switch will enable warnings to be displayed. I HIGHLY recommend using this switch ALL the time!!!

Other Switches Of Interest

-c
causes Perl to check the syntax of the script and then exit without executing it. Actually, it will execute BEGIN and use blocks, since these are considered part of the compilation.
-e commandline
may be used to enter one line of script. If -e is given, Perl will not look for a script filename in the argument list. Multiple -e commands may be given to build up a multi-line script. Make sure to use semicolons where you would in a normal program.
-F regexp
specifies a regular expression to split on if -a is also in effect. If regexp has // around it, the slashes will be ignored.
-i extension
specifies that files processed by the <> construct are to be edited in-place. It does this by renaming the input file, opening the output file by the original name, and selecting that output file as the default for print() statements. The extension, if supplied, is added to the name of the old file to make a backup copy. If no extension is supplied, no backup is made. From the shell, saying $ perl -p -i.bak -e "s/foo/bar/; ... " is the same as using the script: #!/usr/bin/perl -pi.bak s/foo/bar/; which is equivalent to #!/usr/bin/perl while (<>) { if ($ARGV ne $oldargv) { rename($ARGV, $ARGV . '.bak'); open(ARGVOUT, ">$ARGV"); select(ARGVOUT); $oldargv = $ARGV; } s/foo/bar/; } continue { print; # this prints to original filename } select(STDOUT); except that the -i form doesn't need to compare $ARGV to $oldargv to know when the filename has changed. It does, however, use ARGVOUT for the selected filehandle. Note that STDOUT is restored as the default output filehandle after the loop. You can use eof without parenthesis to locate the end of each input file, in case you want to append to each file, or reset line numbering (see example in eof ).
-I directory
may be used in conjunction with -P to tell the C preprocessor where to look for include files. By default /usr/include and /usr/lib/perl are searched.
-n
causes Perl to assume the following loop around your script, which makes it iterate over filename arguments somewhat like sed -n or awk: while (<>) { ... # your script goes here }
-p
causes Perl to assume the following loop around your script, which makes it iterate over filename arguments somewhat like sed: while (<>) { ... # your script goes here } continue { print; }
-S
makes Perl use the PATH environment variable to search for the script (unless the name of the script starts with a slash). Typically this is used to emulate #! startup on machines that don't support #!, in the following manner: #!/usr/bin/perl eval "exec /usr/bin/perl -S $0 $*" if $running_under_some_shell;
-v
prints the version and patchlevel of your Perl executable.


Beginning | Previous | Next
Last Modified: $Date: 1997/05/02 07:17:36 $