Difference between revisions of "Perl"

From Organic Design wiki
(Basic DBI tutorial)
(from regex page)
Line 1: Line 1:
 
{{stub}}
 
{{stub}}
 +
== Perl one liners ==
 +
If you type;
 +
<source lang="perl">
 +
perl --help
 +
</source>
 +
 +
on the command line, Perl will provide details on its usage and command line switches. The switches we are interested in are
 +
<pre>
 +
  -d[:debugger]  run program under debugger
 +
  -e program      one line of program (several -e's allowed, omit programfile)
 +
  -n              assume 'while (<>) { ... }' loop around program
 +
</pre>
 +
 +
== Using -e switch ==
 +
<source lang="perl">
 +
# Unix/Linux
 +
perl -e 'print "It matches\n" if "Hello World" =~ /World/;'
 +
# Windows
 +
perl -e "print \"It matches\n\" if "Hello World" =~ /World/;"
 +
</source>
 +
* See [http://www.perlmonks.org/?node_id=945 string literals] for details on differences between single and double quotes.
 +
 +
== Using -de switch ==
 +
To initiate the debugger for a one line program type;
 +
<source lang="perl">
 +
perl -de 42
 +
</source>
 +
 +
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
 +
 +
== See also ==
 
*[[:Category:PERL|Our Perl scripts]]
 
*[[:Category:PERL|Our Perl scripts]]
 
*[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]]
 +
 
[[Category:Programming languages]]
 
[[Category:Programming languages]]

Revision as of 19:10, 21 September 2015

Cone.png This article or section is a stub. Stubs are articles that have not yet received substantial attention from the authors. They are short or insufficient pieces of information and require additions to further increase the article's usefulness. The project values stubs as useful first steps toward complete articles.

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

See also