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?
perl -v
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..

Hash initialisation:
%particle = (
‘index’ => ‘Bob’,
‘speed’ => 89,
‘test2’ => 76,
‘test3’ => 0);



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: