I’ve decided to dump Perl for intermediate data analysis and random scripty jobs in favour of python. Python just seems more polished, a little more structured (which is good for me, because I don’t want to have to be an expert), and much better support for numerical work.
For numerical work, Perl Data Language (PDL) looked pretty much essential, but the syntax was alien to me, and the benefit not particularly clear.
Anyhow, here are my, possibly completely useless, perl notes.
What version of perl is installed?
A single unit of data in perl is the scalar. A list is an ordered group of scalars, a hash is an unorderd, indexed group of scalars.
A scalar is a single piece of data, of no specific type. A scalar starts with the character $.
Assignment is indentical to other modern languages.
Single and double quoted strings are treated differently wrt to what needs to be escaped. Strings need to be enclosed in quotes to be assigned to variables.
Concatenation of arithmetic with text is performed as follows:
print "product is" . ($number1 * $number2) ."\n";
. is the concatenation operator.
It appears declarations must take place before executable statements.
Array indices start at zero. Arrays (lists) start with the & character. Arrays do not have to contain the same types (you can mix strings and numbers in a list!). Access arrays with c-like syntax $name[index]. The $ sign needs to be added to indicate you are accessing a single variable.
Operations can be performed inside an assignment:
@number = (2*2, 3*3, 4*4);
A hash is indicated by the % symbol. Elements in a hash are name-value pairs. E.g. name,bob,phone,9397890, etc..
%particle = (
‘index’ => ‘Bob’,
‘speed’ => 89,
‘test2’ => 76,
‘test3’ => 0);