

Hash Variables Hashes implement “look-up tables” or “dictionaries” Therefore $#array + 1 is the number of elementsĭoes the same thing and is easier to understand 9] = ('four', 'seven', 'eight', 'nine') ĭoesn't need to be an array ($x, $y) = ($y, $x) Īrray Size $#array is the index of the last element in 140. Setting Array Values $array = 'something' Note use of as we are accessing more than one element of the array 3] # prints 'oranges', 'guavas', # 'passionfruit' Print # prints 'apples', 'guavas', # 'grapes' Note use of $ as individual element of an array is a scalar Īrray Slices Returns a list of elements from an array Print $random_scalars # prints 'dave cross' My = ('mumble', 123.45, 'dave cross', -300, $name) Īrray Elements Accessing individual elements of an array My = ('apples', 'oranges', 'guavas', 'passionfruit', 'grapes') Undefined Values A scalar variable that hasn't had data put into it will contain the special value “undef”Īrray Variables Arrays contain an ordered list of scalar values Print 'He said amp quot The price is 300amp quot ' Use a backslash to escape special characters in double quoted strings Quoting Strings Single quotes don't expand variables or escape sequences Print '$name says, 'The meaning of life is $sum.'' My $sum = $meaning_of_life + $number_less_than_1 Type Conversions Perl converts between strings and numbers whenever necessary My $very_large_number = 3.27e17 # 3.27 times 10 to the power of 17 Scalar Variables Store a single item of data Hash variables start with % More on these types soon ĭeclaring Variables You don't need to declare variables in Perl Types of Perl Variable Different types of variables start with a different symbol Scalar variables start with $ Variable names are preceded by a punctuation mark indicating the type of data User variable names may not start with numbers Variable Names Contain alphanumeric characters and underscores What is a Variable? A place where we can store dataĪ variable needs a name To put new data in it Perl Documentation Perl comes with a huge amount of documentation # This is a hello world program print 'Hello, world!' # print Ĭommand Line Options Many options to control execution of the program Running a Perl Program The 'shebang' line (Unix, not Perl) Running a Perl Program Running a Perl program from the command line The Perl Philosophy There's more than one way to do itĬreating a Perl Program Our first Perl program What is Perl Like? General purpose programming language Less Typical Uses of Perl Human Genome Project Perl's Name Practical Extraction and Reporting Language Resources Slides available on-line Also see Slideshare Get Satisfaction What We Will Cover Conditional Constructs

Introduction to Perl Day 1 An Introduction to Perl Programming Dave Cross Magnum Solutions Ltd
