<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://aznot.com/index.php?action=history&amp;feed=atom&amp;title=UTOSC_2008%2FPerl_Fundamentals</id>
	<title>UTOSC 2008/Perl Fundamentals - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://aznot.com/index.php?action=history&amp;feed=atom&amp;title=UTOSC_2008%2FPerl_Fundamentals"/>
	<link rel="alternate" type="text/html" href="https://aznot.com/index.php?title=UTOSC_2008/Perl_Fundamentals&amp;action=history"/>
	<updated>2026-05-08T23:03:48Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://aznot.com/index.php?title=UTOSC_2008/Perl_Fundamentals&amp;diff=2180&amp;oldid=prev</id>
		<title>Kenneth: Created page with &quot;SelfGOL an entry in Obfuscated Perl Contest  Perl looks like &quot;Line Noise&quot;  It is really really easy to write bad code.  Compared to bash, Perl is very similar with a few chang...&quot;</title>
		<link rel="alternate" type="text/html" href="https://aznot.com/index.php?title=UTOSC_2008/Perl_Fundamentals&amp;diff=2180&amp;oldid=prev"/>
		<updated>2015-05-09T06:56:44Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;SelfGOL an entry in Obfuscated Perl Contest  Perl looks like &amp;quot;Line Noise&amp;quot;  It is really really easy to write bad code.  Compared to bash, Perl is very similar with a few chang...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;SelfGOL an entry in Obfuscated Perl Contest&lt;br /&gt;
&lt;br /&gt;
Perl looks like &amp;quot;Line Noise&amp;quot;&lt;br /&gt;
&lt;br /&gt;
It is really really easy to write bad code.&lt;br /&gt;
&lt;br /&gt;
Compared to bash, Perl is very similar with a few changes.  (ie. echo is now print)&lt;br /&gt;
&lt;br /&gt;
When bash gets any logic, it is time to move on.  Perl is an option.  So is Python and command line PHP.&lt;br /&gt;
&lt;br /&gt;
Very high level language (VHLL)&lt;br /&gt;
&lt;br /&gt;
Perl was originally designed for reporting.&lt;br /&gt;
&lt;br /&gt;
Comments with #.  Exception: #!/usr/bin/perl&lt;br /&gt;
&lt;br /&gt;
&amp;quot;sha-bang&amp;quot; #!&lt;br /&gt;
&lt;br /&gt;
Hello world:&lt;br /&gt;
 #!/usr/bin/perl&lt;br /&gt;
 print &amp;quot;Hello World\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Or&lt;br /&gt;
 perl -e &amp;quot;print &amp;#039;Hello World!&amp;#039;\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Execute single command (for testing purposes):&lt;br /&gt;
 perl -e [command]&lt;br /&gt;
 perl -e &amp;quot;use strict;&amp;quot;&lt;br /&gt;
 perl -e &amp;quot;use DBD::pg;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Code blocks.  Lines should end with &amp;#039;;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Bare words.  Generally no longer allowed:&lt;br /&gt;
 print hello world;&lt;br /&gt;
&lt;br /&gt;
Do in strict syntax.  Don&amp;#039;t allow bare variables.  Require variables to be declared:&lt;br /&gt;
 use strict;&lt;br /&gt;
&lt;br /&gt;
Send to standard error (useful for logging):&lt;br /&gt;
 # includes line number&lt;br /&gt;
 warn &amp;quot;message&amp;quot;;&lt;br /&gt;
 # no line number&lt;br /&gt;
 warn &amp;quot;message\n&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
Exit codes:&lt;br /&gt;
 exit  # return 0&lt;br /&gt;
 exit 42  # return 42&lt;br /&gt;
&lt;br /&gt;
Die (combination of warn and exit 255):&lt;br /&gt;
 die &amp;quot;this is dead&amp;quot;&lt;br /&gt;
 die&lt;br /&gt;
&lt;br /&gt;
Variables:&lt;br /&gt;
*Scalars - standard variable&lt;br /&gt;
*Arrays - indexed list&lt;br /&gt;
*Hashes - named indexed&lt;br /&gt;
&lt;br /&gt;
Scalars&lt;br /&gt;
 $a = &amp;#039;this is a test&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
To convert a string number to a number multiply by 1:&lt;br /&gt;
 $a = &amp;#039;5&amp;#039;;&lt;br /&gt;
 $a = $a * 1;&lt;br /&gt;
&lt;br /&gt;
Sigils determining data content.  A sigil is an indicator as to the context of the variable that you are working with:&lt;br /&gt;
* $ scalar&lt;br /&gt;
* @ array&lt;br /&gt;
* % hashes&lt;br /&gt;
&lt;br /&gt;
String concatenation:&lt;br /&gt;
 $a = &amp;quot;hello&amp;quot; . &amp;quot;world&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
PHP is based off of Perl&lt;br /&gt;
*dot &amp;#039;.&amp;#039; string concatination&lt;br /&gt;
*dollar sign variables&lt;br /&gt;
*die command&lt;br /&gt;
&lt;br /&gt;
Single vs double quotes.  Double quotes evaluate variables and escape characters.  Single quote treats as exact. (except single quote can be ie &amp;#039;bob\&amp;#039;s name&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
Traditional operators:&lt;br /&gt;
* +, -, *, /&lt;br /&gt;
&lt;br /&gt;
Space saving operators:&lt;br /&gt;
* +=, -=, *=, /=&lt;br /&gt;
* ++, --&lt;br /&gt;
&lt;br /&gt;
Arrays (zero based):&lt;br /&gt;
 @a = (0, 1, &amp;quot;two&amp;quot;, 3, 4, 5); # create array&lt;br /&gt;
 print @a[1..4];              # slice 1 - 4&lt;br /&gt;
 print $a[3];                 # scalar 3&lt;br /&gt;
 $a[4] = &amp;quot;four&amp;quot;;              # arrays are mutable;&lt;br /&gt;
 push $a, &amp;quot;six&amp;quot;, 7, &amp;quot;eight&amp;quot;;  # append to array&lt;br /&gt;
 &lt;br /&gt;
 @b = (9, 10);                # create second array&lt;br /&gt;
 @c = (@a, @b);               # create array of array&lt;br /&gt;
 push @a, @b;                 # append @b to @a&lt;br /&gt;
 &lt;br /&gt;
 use Data::Dumper;&lt;br /&gt;
 print Dumper( @a );          # print @a in formatted list&lt;br /&gt;
&lt;br /&gt;
Foreach:&lt;br /&gt;
 foreach $a ( @a ) {&lt;br /&gt;
   print $a . &amp;quot;\n&amp;quot;;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 # $_ (default variable) is last variable used&lt;br /&gt;
 foreach ( @a ) {&lt;br /&gt;
   print $_ . &amp;quot;\n&amp;quot;;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 # for and foreach are interchangable&lt;br /&gt;
 print &amp;quot;$_\n&amp;quot; for @a;         # compressed foreach&lt;br /&gt;
&lt;br /&gt;
Join and Split:&lt;br /&gt;
 print join(&amp;#039;, &amp;#039;, @a);&lt;br /&gt;
 &lt;br /&gt;
 # join turns a list into a scalar&lt;br /&gt;
 $c = join(&amp;#039;:&amp;#039;, @a);&lt;br /&gt;
 # split turns a scalar into a list&lt;br /&gt;
 @d = split(/:/, $c);         # opposite of join&lt;br /&gt;
&lt;br /&gt;
Hashes (associative array):&lt;br /&gt;
 %a = (&lt;br /&gt;
      &amp;#039;father&amp;#039;, &amp;#039;anakin&amp;#039;,&lt;br /&gt;
      &amp;#039;son&amp;#039;, &amp;#039;luke&amp;#039;,&lt;br /&gt;
 );  # can leave comma in last list;&lt;br /&gt;
 &lt;br /&gt;
 %a = (&lt;br /&gt;
      &amp;#039;father&amp;#039; =&amp;gt; &amp;#039;anakin&amp;#039;,&lt;br /&gt;
      &amp;#039;son&amp;#039;    =&amp;gt; &amp;#039;luke&amp;#039;,&lt;br /&gt;
 );  # can leave comma in last list;&lt;br /&gt;
 &lt;br /&gt;
 print $a{&amp;#039;father&amp;#039;};&lt;br /&gt;
 &lt;br /&gt;
 print &amp;quot;$a{$_}&amp;quot; for keys %a;&lt;br /&gt;
&lt;br /&gt;
List environment variables:&lt;br /&gt;
 # todo&lt;br /&gt;
&lt;br /&gt;
Perl can handle decimals.  Bash can only do integers.&lt;br /&gt;
&lt;br /&gt;
Conditionals:&lt;br /&gt;
 %jedi = (&lt;br /&gt;
      &amp;#039;father&amp;#039; =&amp;gt; &amp;#039;anakin&amp;#039;,&lt;br /&gt;
      &amp;#039;son&amp;#039;    =&amp;gt; &amp;#039;luke&amp;#039;,&lt;br /&gt;
 );&lt;br /&gt;
 &lt;br /&gt;
 if ( $jedi{father} eq &amp;#039;anakin&amp;#039; ) { ... }&lt;br /&gt;
 elseif (...) { ... }&lt;br /&gt;
 else { ... }&lt;br /&gt;
&lt;br /&gt;
Comparison:&lt;br /&gt;
* eq for strings&lt;br /&gt;
* == for numbers&lt;br /&gt;
&lt;br /&gt;
Numbers:&lt;br /&gt;
 $a = 1;&lt;br /&gt;
 $b = 2;&lt;br /&gt;
 if ($a = $b) { ... }  # BAD CODE!  force equal&lt;br /&gt;
 if ($a == $b) { ... }   # ok code&lt;br /&gt;
&lt;br /&gt;
For loop counter:&lt;br /&gt;
 #todo&lt;/div&gt;</summary>
		<author><name>Kenneth</name></author>
	</entry>
</feed>