This document provides an overview of the Perl programming language. It introduces key Perl concepts like data types, scalars, arrays, hashes, flow control, input/output, and operators. Perl allows variables to be of any type and handles automatic type conversion. It supports common data structures like arrays and associative arrays (hashes). Subroutines provide modularity and scoping rules determine variable visibility. Perl scripts can process command line arguments, files, and network connections.
The document provides an agenda for a two-day Perl training course. Day 1 will cover Perl fundamentals like scalars, arrays, hashes, subroutines, modules, and advanced data structures. Day 2 will focus on bioinformatics with Bioperl, including finding modules and methods, sequence processing, and visualization. The document outlines topics like variables, lists, functions, operators, and using the perldoc system for documentation.
This is the third set of slightly updated slides from a Perl programming course that I held some years ago.
I want to share it with everyone looking for intransitive Perl-knowledge.
A table of content for all presentations can be found at i-can.eu.
The source code for the examples and the presentations in ODP format are on https://github.com/kberov/PerlProgrammingCourse
Perl, a cross-platform, open-source computer programming language used widely in the commercial and private computing sectors. Perl is a favourite among Web developers for its flexible, continually evolving text-processing and problem-solving capabilities.
This document provides information about arrays in PHP. It discusses numeric arrays, associative arrays, and multidimensional arrays. It explains how to create, iterate through, modify, and handle arrays in PHP. Various functions are described, including count(), print_r(), foreach(), array_slice(), and array_merge(). Multidimensional arrays are given as examples to demonstrate nested arrays and how to access elements within them using loops. Methods for splitting and merging arrays are also covered.
This document discusses PHP functions and arrays. It covers basic syntax for defining functions, returning values from functions, and variable scope. It also covers array basics like indexing and printing arrays, as well as operations like sorting, searching, and iterating over arrays. Functions for stacks, queues and sets using arrays are also demonstrated. The document is a comprehensive reference for working with functions and arrays in PHP.
This is the ninth set of slightly updated slides from a Perl programming course that I held some years ago.
I want to share it with everyone looking for intransitive Perl-knowledge.
A table of content for all presentations can be found at i-can.eu.
The source code for the examples and the presentations in ODP format are on https://github.com/kberov/PerlProgrammingCourse
If your not using an ORM (object relational mapper) and are still writing SQL by hand, here's what you need to know.
An introduction into DBIx::Class and some of the concepts and goodies you should be aware off.
This document provides an overview of PHP arrays, including:
- Arrays allow storing multiple elements that are accessed via numeric indexes. Elements can be of any type.
- Arrays can be iterated over using foreach loops or traditional for/while loops.
- Arrays have built-in functions for sorting, searching, merging, reversing, and more.
- Multidimensional arrays allow storing other arrays as elements.
- Associative arrays use named keys instead of numeric indexes to access elements.
- Exercises demonstrate creating multidimensional arrays and outputting array data to HTML tables.
The document provides an agenda for a two-day Perl training course. Day 1 will cover Perl fundamentals like scalars, arrays, hashes, subroutines, modules, and advanced data structures. Day 2 will focus on bioinformatics with Bioperl, including finding modules and methods, sequence processing, and visualization. The document outlines topics like variables, lists, functions, operators, and using the perldoc system for documentation.
This is the third set of slightly updated slides from a Perl programming course that I held some years ago.
I want to share it with everyone looking for intransitive Perl-knowledge.
A table of content for all presentations can be found at i-can.eu.
The source code for the examples and the presentations in ODP format are on https://github.com/kberov/PerlProgrammingCourse
Perl, a cross-platform, open-source computer programming language used widely in the commercial and private computing sectors. Perl is a favourite among Web developers for its flexible, continually evolving text-processing and problem-solving capabilities.
This document provides information about arrays in PHP. It discusses numeric arrays, associative arrays, and multidimensional arrays. It explains how to create, iterate through, modify, and handle arrays in PHP. Various functions are described, including count(), print_r(), foreach(), array_slice(), and array_merge(). Multidimensional arrays are given as examples to demonstrate nested arrays and how to access elements within them using loops. Methods for splitting and merging arrays are also covered.
This document discusses PHP functions and arrays. It covers basic syntax for defining functions, returning values from functions, and variable scope. It also covers array basics like indexing and printing arrays, as well as operations like sorting, searching, and iterating over arrays. Functions for stacks, queues and sets using arrays are also demonstrated. The document is a comprehensive reference for working with functions and arrays in PHP.
This is the ninth set of slightly updated slides from a Perl programming course that I held some years ago.
I want to share it with everyone looking for intransitive Perl-knowledge.
A table of content for all presentations can be found at i-can.eu.
The source code for the examples and the presentations in ODP format are on https://github.com/kberov/PerlProgrammingCourse
If your not using an ORM (object relational mapper) and are still writing SQL by hand, here's what you need to know.
An introduction into DBIx::Class and some of the concepts and goodies you should be aware off.
This document provides an overview of PHP arrays, including:
- Arrays allow storing multiple elements that are accessed via numeric indexes. Elements can be of any type.
- Arrays can be iterated over using foreach loops or traditional for/while loops.
- Arrays have built-in functions for sorting, searching, merging, reversing, and more.
- Multidimensional arrays allow storing other arrays as elements.
- Associative arrays use named keys instead of numeric indexes to access elements.
- Exercises demonstrate creating multidimensional arrays and outputting array data to HTML tables.
The document discusses different types of arrays in PHP, including numeric index arrays, associative arrays, and multidimensional arrays. Numeric index arrays use integers to identify array elements, associative arrays use named keys, and multidimensional arrays contain arrays within other arrays. Examples are provided for each type of array to demonstrate their syntax and usage.
This document provides an introduction and overview of DBIx::Class, an ORM (object relational mapper) for Perl. It discusses setting up tables for an authors and books example database, and performing CRUD (create, read, update, delete) operations both manually using SQL and using DBIx::Class. It also covers creating models with Schema::Loader, debugging, overloading result and result set classes, and inflating/deflating columns.
This is the seventh set of slightly updated slides from a Perl programming course that I held some years ago.
I want to share it with everyone looking for intransitive Perl-knowledge.
A table of content for all presentations can be found at i-can.eu.
The source code for the examples and the presentations in ODP format are on https://github.com/kberov/PerlProgrammingCourse
This is the second set of slightly updated slides from a Perl programming course that I held some years ago.
I want to share it with everyone looking for intransitive Perl-knowledge.
A table of content for all presentations can be found at i-can.eu.
The source code for the examples and the presentations in ODP format are on https://github.com/kberov/PerlProgrammingCourse
PHP provides several functions for sorting arrays, including sort(), asort(), rsort(), and arsort(). sort() arranges elements in ascending order, asort() maintains index positions during sorting, rsort() sorts in descending order, and arsort() maintains indexes during reverse sorting. These functions allow rearranging array elements alphabetically or numerically into a specified order for easier analysis.
The document discusses various PHP array functions including:
- Array functions like array_combine(), array_count_values(), array_diff() for comparing and merging arrays.
- Sorting arrays with asort(), arsort(), ksort(), krsort().
- Other functions like array_search(), array_sum(), array_rand() for searching, summing and random values.
- Modifying arrays with array_push(), array_pop(), array_shift() for adding/removing elements.
The document provides examples of using each array function in PHP code snippets.
This document provides information on working with arrays in PHP. It discusses the different types of arrays (indexed and associative), how to access and store data in arrays, add and remove values, traverse arrays using foreach loops, and several useful array functions like count(), range(), list(), array_slice(), array_merge(), array_sum(), array_unique(), array_flip(), and extract().
This document provides an overview of hashes in Perl programming. It defines a hash as a set of key-value pairs where keys are not pre-declared and can be created during assignment. Functions for working with hash elements include exists(), defined(), and delete(). Other hash functions include each() to iterate over elements, keys() to return a list of all keys, and values() to return a list of all values.
Arrays allow storing multiple values in a single variable. There are indexed arrays which use numeric indices and associative arrays which use named keys. Arrays can be defined using the array() function or by directly assigning values. Arrays can be looped through using foreach loops or functions like sizeof() to get the size. Multidimensional arrays store arrays within other arrays.
An array is a data structure that stores multiple values in a single variable. There are two main types of arrays in PHP: indexed arrays which use integers as keys and associative arrays which use named keys like strings. The document discusses how to define, access, iterate through and perform operations on arrays in PHP such as counting elements and checking if a key exists.
This document discusses PHP arrays. It begins by defining what arrays are and their uses. It then covers indexed arrays versus associative arrays. The document demonstrates how to store and retrieve data from one-dimensional arrays. It also shows how to create and access multi-dimensional arrays. Various PHP array functions are also explained, including range(), count(), and array_pad(). The document provides examples for each topic to illustrate how arrays work in PHP.
The document discusses several topics related to using Perl for bioinformatics lessons including:
- Providing lesson materials and additional educational resources online
- Benefits of using web technology like having questions answered online and avoiding repetitive questions
- Practicum details like introductions, assignments, and locations
- An introduction to the Perl programming language including its history, uses, and advantages for bioinformatics tasks
- Examples of bioinformatics problems that can be solved using Perl like sequence analysis, parsing results, and database queries
This document summarizes the key topics that will be covered in an introduction to Perl programming course on day 2, including types of variables, references, sorting, and object orientation. The schedule outlines times for lectures, breaks and lunch. Resources provided include slides, slideshare, and an online community.
PHP arrays can be indexed or associative. Indexed arrays are similar to conventional programming language arrays while associative arrays are like dictionaries or maps where elements can be accessed by keys. Array elements can be of any type and arrays can be heterogeneous. PHP provides many functions for manipulating arrays like count(), sizeof(), array_slice(), in_array(), sorting functions, and more.
PHP strings allow storing and manipulating text data. A string is a series of characters that can contain any number of characters limited only by available memory. Strings can be written using single quotes, double quotes, or heredoc syntax. Special characters in strings must be escaped using a backslash. PHP provides many built-in functions for working with strings like concatenation, comparison, searching, replacing, extracting, splitting, joining, formatting and more. Regular expressions provide powerful pattern matching capabilities for strings and PHP has functions like preg_match() for searching strings using regex patterns.
This document provides an overview and schedule for a one-day introduction to Perl programming course. It covers what will be taught including creating and running Perl programs, variables, operators, functions, input/output, and more. The schedule includes breaks and lunch and notes resources available online for the slides.
What makes your code slow? How do you make it faster? And how do you prove it?
This talk will describe my adventures benchmarking and optimizing ordered hashes in Perl, culminating in the release of Hash::Ordered (http://p3rl.org/Hash::Ordered) — which outperforms all other CPAN alternatives, often by a substantial margin. We will cover:
* How to customize Benchmark.pm
* How and why to benchmark at different scales
* Why tied anything in Perl is a horrible idea
* How ordered hashes got faster from a simple algorithm change
This document provides an overview of the Perl programming language. It covers what Perl is, how to create and run Perl scripts, scalar and array variables, hashes, control structures like if/else and loops, file operations, and common Perl functions like split and join. Advanced Perl concepts like subroutines, regular expressions, and object-oriented programming are also mentioned. Resources for learning more about Perl like documentation, books, and mailing lists are provided at the end.
The document provides an overview of the topics to be covered in a basic Perl programming course, including an introduction to Perl, variables, control structures, loops, subroutines, regular expressions, Boolean logic, and file handling. The agenda lists the main topics as Perl introduction, variables, control structures, loops, defining and using subroutines, regular expressions, using Boolean logic for true/false conditions, and file handling. Examples are then provided for many of the programming concepts.
Crash Course in Perl – Perl tutorial for C programmersGil Megidish
Perl is an interpreted programming language created by Larry Wall in 1987. It has been in production longer than PHP, Java, and Ruby. Perl is loosely typed and supports scalars, arrays, hashes, and references. It has a large collection of modules available on CPAN that make it suitable for tasks ranging from databases to web development. Perl code is portable across operating systems and has a friendly community for support.
This document provides an introduction to Perl programming by discussing what Perl is used for, why it is useful, and how to get started with the language. It covers installing Perl on Windows and Linux, using variables and data structures like scalars, arrays, hashes, and references. It also demonstrates basic Perl syntax like conditional statements, loops, file I/O, and running commands. The goal is to get readers writing basic Perl code quickly while highlighting some key features of the language.
Perl was created by Larry Wall as a scripting language that combines features from C, sed, awk, and tcl. It can be used for text processing and system administration tasks. Some key points about Perl include:
- Perl scripts have a .pl extension and are executed using the perl command. It supports scalar variables like numbers and strings as well as arrays to hold lists of data.
- Common data types in Perl include scalars for single values, arrays for lists, and associative arrays for key-value pairs. Perl also has regular expressions for complex text parsing and manipulation.
- Perl provides functions for sorting, reversing, and manipulating arrays. Regular expressions can be used to search for patterns and
The document discusses different types of arrays in PHP, including numeric index arrays, associative arrays, and multidimensional arrays. Numeric index arrays use integers to identify array elements, associative arrays use named keys, and multidimensional arrays contain arrays within other arrays. Examples are provided for each type of array to demonstrate their syntax and usage.
This document provides an introduction and overview of DBIx::Class, an ORM (object relational mapper) for Perl. It discusses setting up tables for an authors and books example database, and performing CRUD (create, read, update, delete) operations both manually using SQL and using DBIx::Class. It also covers creating models with Schema::Loader, debugging, overloading result and result set classes, and inflating/deflating columns.
This is the seventh set of slightly updated slides from a Perl programming course that I held some years ago.
I want to share it with everyone looking for intransitive Perl-knowledge.
A table of content for all presentations can be found at i-can.eu.
The source code for the examples and the presentations in ODP format are on https://github.com/kberov/PerlProgrammingCourse
This is the second set of slightly updated slides from a Perl programming course that I held some years ago.
I want to share it with everyone looking for intransitive Perl-knowledge.
A table of content for all presentations can be found at i-can.eu.
The source code for the examples and the presentations in ODP format are on https://github.com/kberov/PerlProgrammingCourse
PHP provides several functions for sorting arrays, including sort(), asort(), rsort(), and arsort(). sort() arranges elements in ascending order, asort() maintains index positions during sorting, rsort() sorts in descending order, and arsort() maintains indexes during reverse sorting. These functions allow rearranging array elements alphabetically or numerically into a specified order for easier analysis.
The document discusses various PHP array functions including:
- Array functions like array_combine(), array_count_values(), array_diff() for comparing and merging arrays.
- Sorting arrays with asort(), arsort(), ksort(), krsort().
- Other functions like array_search(), array_sum(), array_rand() for searching, summing and random values.
- Modifying arrays with array_push(), array_pop(), array_shift() for adding/removing elements.
The document provides examples of using each array function in PHP code snippets.
This document provides information on working with arrays in PHP. It discusses the different types of arrays (indexed and associative), how to access and store data in arrays, add and remove values, traverse arrays using foreach loops, and several useful array functions like count(), range(), list(), array_slice(), array_merge(), array_sum(), array_unique(), array_flip(), and extract().
This document provides an overview of hashes in Perl programming. It defines a hash as a set of key-value pairs where keys are not pre-declared and can be created during assignment. Functions for working with hash elements include exists(), defined(), and delete(). Other hash functions include each() to iterate over elements, keys() to return a list of all keys, and values() to return a list of all values.
Arrays allow storing multiple values in a single variable. There are indexed arrays which use numeric indices and associative arrays which use named keys. Arrays can be defined using the array() function or by directly assigning values. Arrays can be looped through using foreach loops or functions like sizeof() to get the size. Multidimensional arrays store arrays within other arrays.
An array is a data structure that stores multiple values in a single variable. There are two main types of arrays in PHP: indexed arrays which use integers as keys and associative arrays which use named keys like strings. The document discusses how to define, access, iterate through and perform operations on arrays in PHP such as counting elements and checking if a key exists.
This document discusses PHP arrays. It begins by defining what arrays are and their uses. It then covers indexed arrays versus associative arrays. The document demonstrates how to store and retrieve data from one-dimensional arrays. It also shows how to create and access multi-dimensional arrays. Various PHP array functions are also explained, including range(), count(), and array_pad(). The document provides examples for each topic to illustrate how arrays work in PHP.
The document discusses several topics related to using Perl for bioinformatics lessons including:
- Providing lesson materials and additional educational resources online
- Benefits of using web technology like having questions answered online and avoiding repetitive questions
- Practicum details like introductions, assignments, and locations
- An introduction to the Perl programming language including its history, uses, and advantages for bioinformatics tasks
- Examples of bioinformatics problems that can be solved using Perl like sequence analysis, parsing results, and database queries
This document summarizes the key topics that will be covered in an introduction to Perl programming course on day 2, including types of variables, references, sorting, and object orientation. The schedule outlines times for lectures, breaks and lunch. Resources provided include slides, slideshare, and an online community.
PHP arrays can be indexed or associative. Indexed arrays are similar to conventional programming language arrays while associative arrays are like dictionaries or maps where elements can be accessed by keys. Array elements can be of any type and arrays can be heterogeneous. PHP provides many functions for manipulating arrays like count(), sizeof(), array_slice(), in_array(), sorting functions, and more.
PHP strings allow storing and manipulating text data. A string is a series of characters that can contain any number of characters limited only by available memory. Strings can be written using single quotes, double quotes, or heredoc syntax. Special characters in strings must be escaped using a backslash. PHP provides many built-in functions for working with strings like concatenation, comparison, searching, replacing, extracting, splitting, joining, formatting and more. Regular expressions provide powerful pattern matching capabilities for strings and PHP has functions like preg_match() for searching strings using regex patterns.
This document provides an overview and schedule for a one-day introduction to Perl programming course. It covers what will be taught including creating and running Perl programs, variables, operators, functions, input/output, and more. The schedule includes breaks and lunch and notes resources available online for the slides.
What makes your code slow? How do you make it faster? And how do you prove it?
This talk will describe my adventures benchmarking and optimizing ordered hashes in Perl, culminating in the release of Hash::Ordered (http://p3rl.org/Hash::Ordered) — which outperforms all other CPAN alternatives, often by a substantial margin. We will cover:
* How to customize Benchmark.pm
* How and why to benchmark at different scales
* Why tied anything in Perl is a horrible idea
* How ordered hashes got faster from a simple algorithm change
This document provides an overview of the Perl programming language. It covers what Perl is, how to create and run Perl scripts, scalar and array variables, hashes, control structures like if/else and loops, file operations, and common Perl functions like split and join. Advanced Perl concepts like subroutines, regular expressions, and object-oriented programming are also mentioned. Resources for learning more about Perl like documentation, books, and mailing lists are provided at the end.
The document provides an overview of the topics to be covered in a basic Perl programming course, including an introduction to Perl, variables, control structures, loops, subroutines, regular expressions, Boolean logic, and file handling. The agenda lists the main topics as Perl introduction, variables, control structures, loops, defining and using subroutines, regular expressions, using Boolean logic for true/false conditions, and file handling. Examples are then provided for many of the programming concepts.
Crash Course in Perl – Perl tutorial for C programmersGil Megidish
Perl is an interpreted programming language created by Larry Wall in 1987. It has been in production longer than PHP, Java, and Ruby. Perl is loosely typed and supports scalars, arrays, hashes, and references. It has a large collection of modules available on CPAN that make it suitable for tasks ranging from databases to web development. Perl code is portable across operating systems and has a friendly community for support.
This document provides an introduction to Perl programming by discussing what Perl is used for, why it is useful, and how to get started with the language. It covers installing Perl on Windows and Linux, using variables and data structures like scalars, arrays, hashes, and references. It also demonstrates basic Perl syntax like conditional statements, loops, file I/O, and running commands. The goal is to get readers writing basic Perl code quickly while highlighting some key features of the language.
Perl was created by Larry Wall as a scripting language that combines features from C, sed, awk, and tcl. It can be used for text processing and system administration tasks. Some key points about Perl include:
- Perl scripts have a .pl extension and are executed using the perl command. It supports scalar variables like numbers and strings as well as arrays to hold lists of data.
- Common data types in Perl include scalars for single values, arrays for lists, and associative arrays for key-value pairs. Perl also has regular expressions for complex text parsing and manipulation.
- Perl provides functions for sorting, reversing, and manipulating arrays. Regular expressions can be used to search for patterns and
Perl was created by Larry Wall as a scripting language that combines features from C, sed, awk, and tcl. It can be used for text processing and system management tasks. Some key points about Perl include:
- Perl scripts have a .pl extension and are executed using the perl command. It supports scalar variables like numbers and strings as well as arrays to hold lists of data.
- Common data types in Perl include scalars for single values, arrays for lists, and associative arrays for key-value pairs. Strings can be delimited by single or double quotes.
- Perl provides functions for text manipulation like regular expressions, substitution, splitting strings. Arrays can be sorted, reversed, and
The document summarizes a Perl Mongers course on data and operators in Perl. It covers basic data types like scalars, arrays, and hashes. It describes strings, numbers, and how to perform operations on them. It also discusses control structures like conditionals and loops for program flow. Finally, it mentions input/output functions like STDIN and STDOUT.
This document provides an overview of the Perl programming language. It discusses that Perl uses an interpreter to run code without compilation, and that it is easy to learn, program, and debug in Perl. The document then covers Perl installation, variables, data types, control structures, modules, and provides an example of a basic phonebook program to demonstrate hashes.
These are the lecture slides for the BITS training session "Introduction to programming in Bioperl".
See for more material: http://www.bits.vib.be/index.php?option=com_content&view=article&id=17203793:bioperl-additional-material&catid=84&Itemid=610
This document provides an overview of key Perl concepts including scalars, arrays, hashes, I/O, operators, and control structures. It discusses scalar data types like strings and numbers. It also covers arrays, hashes, and common functions for each. The document outlines I/O with the console, files, and handles. It briefly summarizes operators and precedence. Finally, it discusses control structures like if/else, loops, and modifiers.
The document discusses Perl arrays, scalars, and constants. Some key points:
- Arrays are prefixed with @ and hold a list of scalars. They can be assigned using @var = (value1, value2).
- Scalars represent a single value and are used to hold individual elements of an array.
- Constants are values that don't change, like numbers or defined strings. They don't require $ or @ prefixes.
The document provides tips for writing simple, readable code that is easy to maintain and adapt to changes over time. It emphasizes keeping code well-structured with small, single-purpose functions and classes, using good naming conventions, testing code, and designing for flexibility through techniques like dependency injection and interfaces. The document also encourages practicing code through katas and code reviews to improve coding skills.
This document provides an introduction to Perl and BioPerl for bioinformatics. It discusses Jennifer Dommer and Vivek Gopalan from the National Institute of Allergy and Infectious Diseases presenting on Perl programming principles including variables, flow control, loops, file manipulation and regular expressions. It then provides an overview of BioPerl and how it can be used for tasks like working with sequence data. Examples are given throughout to demonstrate various Perl coding concepts.
Full-day tutorial for the dutch php conference 2011 giving a very quick tour around all the various areas of the ZCE syllabus and some tips on the exam styles
This document provides a summary of a tutorial on learning the Perl 6 programming language. It covers topics like scalars, variables, control structures, I/O, subroutines, regular expressions, modules, classes and objects. It suggests that in the 80 minute session, the presenters will be able to cover data, variables, control structures, I/O, subroutines and regular expressions, but may not have time for everything. It also provides information on getting started with Pugs and writing simple Perl 6 programs, as well as examples of core Perl 6 concepts like objects, methods, strings, arithmetic, conditionals and loops.
This document provides an overview of the Perl programming language and includes examples of common Perl scripts and functions. It discusses getting started with Perl, printing, variables, arrays, loops, conditionals, regular expressions, file handling and subroutines. Code snippets are provided to demonstrate concepts like opening and reading files, splitting strings, calculating averages and more. The document serves as a tutorial for beginners to learn the basics of Perl programming.
This document provides an overview of the Perl programming language and includes examples of common Perl constructs. It discusses getting started with Perl, printing, variables, arrays, loops, conditionals, regular expressions, file handling and subroutines. Code snippets are provided to demonstrate various Perl features such as accessing array elements, for/while loops, pattern matching with regular expressions, splitting strings, and defining subroutines.
The document discusses Perl control structures and arrays. It explains that a statement block contains a sequence of statements enclosed in curly braces. It also discusses if/else conditional statements and unless conditional statements. The document then explains that arrays are a special type of variable that stores list data types, with each element being a string, number, or other scalar. Array variables are prefixed with an @ symbol. It provides examples of defining and accessing array elements and using array slices.
This document provides an overview of PHP and MySQL. It discusses key PHP elements like variables, arrays, conditional statements, and loops. It also covers PHP statements, naming variables, outputting values, performing calculations, working with arrays, conditional logic, and loops. The document then discusses connecting to and querying MySQL databases, and how to insert, update, delete data. It also covers building forms, getting form input, and basic file input/output in PHP.
1. PHP is a loosely typed scripting language that is case sensitive. It uses variables prefixed with $ to store values of different data types like strings, integers, floats, booleans, arrays and objects.
2. PHP supports many control structures like conditional statements, loops and functions. Functions allow grouping reusable blocks of code and can take arguments and return values.
3. Arrays can be indexed or associative and store multiple values. Multidimensional arrays can hold arrays within arrays.
This document provides an overview of the Perl programming language. It discusses key Perl concepts like numbers, strings, variables, arrays, comparison operators, and control structures. Some key points covered include how Perl handles numeric and string data types, how to define and assign variables, how to perform basic operations on numbers and strings, and how to use common control structures like if/else, while loops, and foreach loops. The document also provides examples of working with arrays and lists in Perl.
1. Scripting Languages
Perl Basics
Course: 67557
Hebrew University
Lecturer: Elliot Jaffe – אליוט יפה
2. FMTEYEWTK
• Far More Than Everything You've Ever
Wanted to Know
• Perl
– Pathologically Eclectic Rubbish
Lister
– Practical Extraction and Report Language
• The Perl motto is TMTOWTDI
– ``There's more than one way to do it.''
5. Data Types
Values of any type may be stored in a variable
$myVar = 'c'; # Character
$myVar = "Hello World!"; # String
$myVar = 42; # Integer
$myVar = 3.14159; # Float
6. Strings
• Double Quotes strings are interpolated
• Single Quoted strings are static
$myA = ’a’;
$myB = ”this is $myA string”;
$myC =
’this is another $myA string’;
7. Automatic Type Conversion
Conversion happens automatically
From To Conversion
“42” 42 String to Integer
42 “42” Integer to String
“3.14159” 3.14159 String to Float
3.14159 “3.14159” Float to String
“c” ‘c’ String to Char
‘c’ “c” Char to String
8. Perl Data Structures
• Scalar
• Arrays of Scalars
• Associative Arrays of Scalars – Hashes
• Variables are identified by sigil
– a preceding dereferencing symbol which tells
Perl what kind of variable it is
9. Scalars
$myVar = 3.14159;
• Sigil: $
• Holds a single scalar value of any type
• Undefined variables have the value undef
defined(undef) == FALSE
10. Notes
• Notice that we did NOT have to
– declare the variable before using it
– define the variable's data type
– allocate memory for new data values
• Is this a good thing?
11. Arrays of Scalars
@myVar = (3, “foo”, ’c’);
• Sigil: @
• A list of any type of scalar values
$myVar[0] is 3
$myVar[2] is ’c’
• Access to array elements is by integer index
(zero based)
12. More on Arrays
• Creating and setting an element
$foo[3] = "dog";
• Assigning multiple element values
$foo[1,3] = ( "bear", "dear" );
• Adding new elements
@foo = ( @foo, "elk" ); # Append
@foo = ( "ace", @foo ); # Prepend
13. Sizes of Lists
• Two approaches yield two different results
@foo = ( "apple", "bat", "cat" );
• Get the number of elements contained in the list
$size = scalar( @foo ); # Yields 3
• Get the index for the last element contained in the
list
$size = $#foo; # Yields 2
14. Lists as LHS values
• You can use lists on the left-hand side of an
assignment "=" operator
($first, $last) = ("John", "Moreland");
• Perl uses "greedy" assignment for L-Values. Here,
$d is left untouched
($a,$b,@c,$d) = ("a","b","c","d","e");
• But, here, "e" is simply not assigned
($a,$b,$c,$d ) = ("a","b","c","d","e");
15. Range Operators
• Perl defines a special list range operator ".." to
simplify the specification of such a range
• The ".." operator is used as an infix operator
placed between any two scalar values
• Perl will interpolate the (quantized "in between")
values automatically
( 1..5 ) # Yields ( 1, 2, 3, 4, 5 )
( 1.3..6.1 ) # Yields ( 1.3, 2.3, 3.3, 4.3, 5.3 )
( 2..6, 10, 12 ) # Yields ( 2, 3, 4, 5, 6, 10, 12 )
( "a".."z" ) # Yields ( "a", "b", "c", ..., "z" ) Nice.
( "a1".."e9" ) # Yields ( "a1", "a2", ..., "e9" ) Wow!
16. Example
• Put “bat” between (“ape”, “cat”)
@foo = ( "ape", "cat" );
$foo[2] = "cat";
$foo[1] = "bat";
or
$a = shift( @foo );
unshift( @foo, $a, "bat" );
17. Builtin List functions
pop Remove last item $a = pop(@list);
push Insert item at end push(@list, $a);
shift Remote first item $a = shift(@list);
unshift Insert item at front unshift(@list, $a);
splice Remove @olditems =
splice(@list, $pos);
splice Remove n items @olditems =
splice(@list, $pos, $n);
splice Remove and insert @olditems =
splice(@list, $pos, $n,
@newitems);
18. List processing
grep search @code = grep !/^#/, @lines;
join Insert item at end $str = join ’:’, @words;
split Split string @list =
split /[-,]/, “1-10,20”;
# (1, 10, 20)
reverse Reverse list @new = reverse @old;
19. Associative Arrays - Hashes
• Associative arrays are hash tables
• Sigil: %
• Stored as unordered lists of (key, value)
pairs
• Any scalar value can be used as a key
20. Hash examples
• You can initialize an associative array much like a list
%days = ( 'M', "Monday", 'T', "Tuesday");
• The scalar $ plus {} references one element (note: key is
any scalar value)
$days{'W'} = "Wednesday";
• Any scalar data type can be used for the key or the value
$myConst{"PI"} = 3.14159;
$hg{42} = "life, the universe, and me";
21. Builtin Hash Functions
%days = ( 'M', "Monday", 'T', "Tuesday" );
• The keys() function returns a list of keys
@letters = keys( %days );
# Yields ( 'M', 'T' )
• The values() function returns a list of values
@names = values( %days );
# Yields ( "Monday", "Tuesday" )
• The delete() function removes a Key-Value pair
delete( $days{'M'} );
# Yields ( 'T', "Tuesday" )
• The exists() function checks if a key exists in this hash
exists( $days{‘W'} ); # Yields False (0)
23. Subroutines
• Defining
sub MyFunction {
# your code goes here
return $value; # optional
}
• Calling
&MyFunction; # if not yet seen
MyFunction; # if seen
24. Subroutine Parameters
• Calling a function
&MyFunction;
&MyFunction();
&MyFunction($arg1, $arg2);
&MyFunction($arg1, $arg2, @list1);
• The & is optional and deprecated
MyFunction($arg1, $arg2);
25. Subroutine Parameters
• This is probably the ugliest thing in Perl!
• Parameters are stored in the variable @_;
sub MyFunction {
($arg1, $arg2, @list) = @_;
$arg1 = $_[0];
}
– Parameters are passed by value unless
otherwise specified
27. Scoping
• By default, all variables are GLOBAL
• Perl support lexical and dynamically scoped
variables
– Lexical: variable is defined within the textual
block
– Dynamic: variable is defined to all functions
called within this block
28. Global Scoping
$a = “foo”;
sub global {
($arg1) = @_;
print “in global arg1 = $arg1 n”;
nested;
}
sub nested {
print “in nested arg1 = $arg1 n”;
}
global($a);
print “outside arg1 = $arg1 n”;
30. Command line
• Two variables provide Variable Contents
access to command $0 Script name
line arguments
$ARGV[0] First arg
• Slightly different from $ARGV[1] Second arg
the C conventions
31. Flow Control
• No main function
• Statements are executed as they are
encountered in the file
• Subroutines are defined but not executed
• exit() leaves the program
34. One line conditional
• Often used shortcut for if-then (then-if)
$happy = 1;
$good = 1 if $happy;
$bad = 1 if ! $happy;
35. For loop
for ($i = 0; $i < 10; $i++) {
print $i . “n”;
}
for (;;) {
# infinite loop
}
36. Loops
while ( $foo = <FILE> ) {
# do stuff
}
do {
# stuff
} until ($end);
37. foreach
• Loop over a list
@list = (“dog”, “cat”, “fish”);
foreach $f (@list) {
print $f . “n”;
}
38. Special loop modifiers
• next
– Restart loop with the next value
• last
– Exit loop
• redo
– Restart loop with the current value
39. Input/Output
• File handles are pointers to an I/O stream
• By convention they are in UPPERCASE
• No sigil
• Can be a pipe, socket, file
• Standard handles are
– STDIO, STDOUT, STDERR
print STDOUT “Hello World”;
40. open(FILEHANDLE, expression)
• For read:
open(INFILE, “<$fname“);
• For write:
open(OUTFILE, “>$fname);
• For appending
open(OUTFILE, “>>$fname);
• For random access:
open(FILE, “+>$fname”);
47. Comparison operators
Numeric String Two different operator
== eq types are confusing
!= ne
$i = 12;
< lt if ( $foo < 7 )
> gt # FALSE
if ( $foo lt 7 )
<= le # TRUE
>= ge
48. Compound Logical operators
|| OR $apples || $oranges
&& AND $apples && $oranges
! NOT ! $fruit
<=> “Spaceship” -1 if <, 0 if ==, 1 if >
cmp Compare -1 if lt, 0 if eq, 1 if gt