Difference between revisions of "Perl"
From Organic Design wiki
(from regex page) |
(→See also: Quotemeta) |
||
Line 36: | Line 36: | ||
*[http://man7.org/linux/man-pages/man3/strftime.3.html Date formatting symbols] | *[http://man7.org/linux/man-pages/man3/strftime.3.html Date formatting symbols] | ||
*[http://perl.com/pub/1999/10/DBI.html Basic DBI tutorial] | *[http://perl.com/pub/1999/10/DBI.html Basic DBI tutorial] | ||
− | *[[Regular expressions]] | + | *[[Regular expressions]] and [http://perldoc.perl.org/functions/quotemeta.html Quotemeta] |
[[Category:Programming languages]] | [[Category:Programming languages]] |
Revision as of 21:42, 1 April 2016
Perl one liners
If you type;
perl --help
on the command line, Perl will provide details on its usage and command line switches. The switches we are interested in are
-d[:debugger] run program under debugger -e program one line of program (several -e's allowed, omit programfile) -n assume 'while (<>) { ... }' loop around program
Using -e switch
# Unix/Linux
perl -e 'print "It matches\n" if "Hello World" =~ /World/;'
# Windows
perl -e "print \"It matches\n\" if "Hello World" =~ /World/;"
- See string literals for details on differences between single and double quotes.
Using -de switch
To initiate the debugger for a one line program type;
perl -de 42
Now type 'h' to obtain for help commands used within the debugger. Commands useful for one liners in the debugger are;
- 'x' to eval an expression in list context, and print the result.
- 'q' to quit