Difference between revisions of "Perl"

From Organic Design wiki
(See also: Reading and writing UTF-8 examples with IO::All)
(See also: Good blog item on Perl and UTF-8)
Line 38: Line 38:
 
*[[Regular expressions]] and [http://perldoc.perl.org/functions/quotemeta.html Quotemeta]
 
*[[Regular expressions]] and [http://perldoc.perl.org/functions/quotemeta.html Quotemeta]
 
*[https://perl-begin.org/topics/files-and-directories/ Reading and writing UTF-8 examples with IO::All]
 
*[https://perl-begin.org/topics/files-and-directories/ Reading and writing UTF-8 examples with IO::All]
 
+
*[https://blog.summercat.com/perl-and-character-encoding.html Good blog item on Perl and UTF-8]
 
[[Category:Programming languages]]
 
[[Category:Programming languages]]

Revision as of 19:14, 9 January 2019

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