Perl
Total Page:16
File Type:pdf, Size:1020Kb
-I<directory> directories specified by –I are Perl prepended to @INC -I<oct_name> enable automatic line-end processing Ming- Hwa Wang, Ph.D. -(m|M)[- executes use <module> before COEN 388 Principles of Computer- Aided Engineering Design ]<module>[=arg{,arg}] executing your script Department of Computer Engineering -n causes Perl to assume a loop around Santa Clara University -p your script -P causes your script through the C Scripting Languages preprocessor before compilation interpreter vs. compiler -s enable switch parsing efficiency concerns -S makes Perl use the PATH environment strong typed vs. type-less variable to search for the script Perl: Practical Extraction and Report Language -T forces taint checks to be turned on so pattern matching capability you can test them -u causes Perl to dump core after Resources compiling your script Unix Perl manpages -U allow Perl to do unsafe operations Usenet newsgroups: comp.lang.perl -v print version Perl homepage: http://www.perl/com/perl/, http://www.perl.org -V print Perl configuration and @INC Download: http://www.perl.com/CPAN/ values -V:<name> print the value of the named To Run Perl Script configuration value run as command: perl –e ‘print “Hello, world!\n”;’ -w print warning for unused variable, run as scripts (with chmod +x): perl <script> using variable without setting the #!/usr/local/bin/perl –w value, undefined functions, references use strict; to undefined filehandle, write to print “Hello, world!\n”; filehandle which is read-only, using a exit 0; non-number as it were a number, or switches subroutine recurse too deep, etc. -- terminates switch processing -x<directory> tells Perl to extract a script that is -0<oct_name> specifies the record separator ($/) as embedded in a message an octal number debug: perl –d <script> -a truns on autosplit mode when used debugger commands: with a –n or -p commands usage -c causes perl to check the syntax h [command] for help message -d runs the script under the Perl p expr print the expression debugger x expr execute and print the expression -d:<lib_name> runs the script under the control of a debugging/tracing module installed in V [pkg[vars]] display variables Perl library as Devel::<lib_name>, X [vars] same as V currentpkg[vars] e.g., Devel::DProf for profiler T produce stack backtrace -D<number | list> set debugging flags n next -e commandline to enter one or more lines of script <CR> repeat last n or s command -F<pattern> Specifies the pattern to split on if –a c [line] continue [break on line only once] is used - or l [min+incr|min-max| list next few lines -h help line|subname] -i<extension> Specifies that file processed by the < w [line] list window a few lines [around the > construct are to be edited in-place line] . return debugger pointer to the last strict restrict unsafe constructs executed line and print it out Symbol generate anonymous globs; qualify variable f filename switch to view a different file names /pattern/, ?pattern? search forward/backword for pattern subs predeclare subroutine names L list all break points or actions for vars predeclare global variable names current file error handling and logging S[![pattern] list subroutine names [not]matching Carp generate error messages pattern diagnostics force verbose warning diagnostics t toggle trace mode sigtrap enable stack backtrace on unexpected signals t expr trace through execution of expr Sys::Syslog Perl interface to UNIX syslog(3) calls b [subname] [line] set a breakpoint [in subname] [at file access and handling [condition] line] [when condition] Cwd get pathname of current working directory d [line] delete a breakpoint [at line] DirHandle supply object methods for directory handles D delete all installed breakpoints File::Basename parse file specifications a [line] command set an action to be done before the File::CheckTree run many tests on a collection of files line is executed File::Copy copy files or filehandles A delete all installed actions File::Find traverse a file tree O [opt[=val]] set or query values of options File::Path create or remove a series of directories < command set an action to happen before every FileCache keep more files open than the system permits debugger prompt FileHandle supply object methods for filehandles > command set an action to happen after every SelectSaver save and restore selected filehandles debugger prompt test processing and screen interfaces ! [-] number redo a previous commands Pod::Text convert POD data to formatted ASCII text ! pattern redo last command that started with Search::Dict search for key in dictionary file pattern Term::Cap terminal capabilities interface !! command run command in a subprocess Term::Complate word completion module H -number display last number command Text::Abbrev create an abbreviation table from a list q or ^D quit Text::ParseWords parse text into a list of tokens R restart Text::Soundex the soundex algorithm described by Knuth | dbcmd or || dbcmd run debugger cmd piping DB::OUT to Text::Tabs expand and unexpand tabs $ENV{PAGER} Text::Wrap wrap text into a paragraph = [alias value] define a command alias or list database interfaces current aliases AnyDBM_File provide framework for multiple DBMs DB_File tied access to Berkeley DB Pragmas GDBM_File tied access to GDBM library syntax: use module; NDBM_File tied access to NDBM files miscellaneous ODBM_File tied access to ODBM files Benchmark check and compare running times of code SDBM_File tied access to SDBM files Config access Perl configuration information mathematics Env import environment variables integer do arithmetic in integer instead of double English use English or awk names for punctuation Math::BigFloat arbitrary-length floating-point math package variables Math::BigInt arbitrary-length integer match package Getopt::Long extended processing of command-line options Math::Complex complex numbers package Getopt::Std process single-character switches with switch clustering networking and interprocess communication lib manipulate @INC at compile time IPC::Open2 open a process for both reading and writing Shell run shell commands transparently within Perl IPC::Open3 open a process for reading, writing, and error handling Net::Ping check whether a host is online $: scalar variable Socket load the C socket.h defines and structure @: array variable manipulators %: associated array (or hash) variable Sys::Hostname try every conceivable way to get hostname &: subroutine time and locale *: typeglob (references or alias for passing or storing filefolders or Time::Local efficiently computer time from local and GMT time symbol tables) I18N::Collate compare 8-bit scalar data according to the current locale Predefined variables autoloading and dynamic loading (for developers) global special variables AutoLoader load functions only on demand $_($ARG), $.($INPUT_LINE_NUMBER or $NR), $/($INPUT_RECORD_SEPARATOR or $RS), AutoSplit split a module for autoloading $,($OUTPUT_FIELD_SEPARATOR or $OFS), Devel::SelfStubber generate stubs for a SelfLoading module $\($OUTPUT_RECORD_SEPARATOR or $ORS), $”($LIST_SEPARATOR), DynaLoader automatic kynamic loading of Perl modules $;($SUBSCRIPT_SEPARATOR or $SUBSEP), SelfLoader load functions only on demand $:($FORMAT_LINE_BREAK_CHARACTER), $#($OFMT), $[(the index of language extensions and platform development support (for developers) the first element in an array, and of the first character in a substring) ExtUtils::Install install files from here to there regular expression special variables ExtUtils::Liblist determine libraries to use and how to use $&($MATCH), $’($POSTMATCH), $`($PREMATCH), them $+($LAST_PATTERN_MATCH), $*($MULTILINE_MATCHING) ExtUtils::MakeMaker create a Makefile for a Perl extension Perl filehandle special variables ExtUtils::Manifest utilities to write and check a MANIFEST $|($OUTPUT_AUTOFLUSH), $=($OUTPUT_LINE_PER_PAGE), file $%($FORMAT_PAGE_NUMBER), $-($FORMAT_LINE_LEFT), ExtUtils::Miniperl write the C code for perlmain.c $~($FORMAT_NAME), $^($FORMAT_TOP_NAME) ExtUtils::Mkbootstrap make a bootstrap file for use by system special variables Dynaloader $$($PROCESS_ID or $PID), $]($PERL_VERSION), ExtUtils::Mksymlists write linker option files for dynamic $0($PROGRAM_NAME), $@($EVAL_ERROR), $!($OS_ERROR), extension $?($CHILD_ERROR), $<($REAL_USER_ID or $UID), ExtUtils::MM_OS2 methods to override UNIX behavior in $(($REAL_GROUP_ID or $GID), $)($EFFECTIVE_GROUP_ID or $EGID), ExtUtils::MakeMaker $>($EFFECTIVE_USER_ID or $EUID) ExtUtils::MM_Unix methods used by ExtUtils::MakeMaker other global special variables ExtUtils::MM_VMS methods to override UNIX behavior in $^A($ACCUMULATOR), $^D($DEBUGGING), $^F($SYSTEM_FD_MAX), ExtUtils::MakeMaker $^H(internal compiler hints enabled by pragmatic modules), fcntl load the C fcntl.h defines $^I($INPLACE_EDIT), $^L($FORMAT_LINEFEED), $^O($OSNAME), POSIX interface to IEEE Std 1003.1 $^P($PERLDB), $^T($BASETIME), $^W($WARNING), Safe create safe namespaces for evaluating $^X($EXECUTABLE_NAME) Perl code global special arrays Test::Harness run Perl standard test scripts with $ARGC, @ARGV, $#ARGV, @INC(for include paths), @F(when –a option statistics is used), %INC(included headers), %ENV, %SIG object-oriented programming support (for developers) global special filehandles Exporter default import method for modules STDIN, STDOUT, STDERR, __LINE__, __FILE__, __END__, __DATA__ overload overload Perl’s mathematical operations Values Tie::Hash base class definitions for tied hashes assign values: assign scalar to scalar variable, assign array/hash to Tie::Scalar