1 / 12

Introduction to Perl – Part 1

Introduction to Perl – Part 1. Timothy Hahn. Overview. Perl is a really easy, simple scripting language It is very friendly to Unix and other operating systems VERY VERY SIMPLE TO LEARN!!!. Scalar Data. Perl only has two basic data types: numbers and strings

Download Presentation

Introduction to Perl – Part 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Perl – Part 1 Timothy Hahn

  2. Overview • Perl is a really easy, simple scripting language • It is very friendly to Unix and other operating systems • VERY VERY SIMPLE TO LEARN!!!

  3. Scalar Data • Perl only has two basic data types: numbers and strings • Like Python and Ruby, but not like C++ and Java, Perl does not need to have these data types defined before (e.g. int number or String word) • You can just call things without initializing. • In Perl, you use “$” in front of these basic variables. • e.g. $word = “String!”; • When you call something that’s not yet been defined, Perl will use “undef” instead of crashing completely. With words it will be a blank “” string and with numbers it will be 0 • In Perl, you can simply call a variable inside a print command

  4. Scalar Data

  5. Operators • Except for two special operators, Perl has very standard basic operators: • Assignment: = • Arithmetic: +, -, *, / • String: ., x (See example later) • Comparison:

  6. Operators • Except for two special operators, Perl has very standard basic operators: • Assignment: = • Arithmetic: +, -, *, / • String: ., x (See example later) • Comparison:

  7. String Operators • Before I go into string operators, Perl automatically can convert numbers to strings. So the number 5 can be used with these string operators • “.” is a string operator that appends the left hand string to the right hand string • “x” is a string operator that prints the left hand string by the right hand number

  8. String Operators

  9. Input • Two Methods to doing input: • <STDIN> and <>

  10. Input Shortcut • Using $_ • Just a faster shortcut

  11. Lists • Lists are placed in ( ) • A list of integers from 1 to 10 can be represented as: • (1,2,3,4,5,6,7,8,9,10) • (1..10) • Useful for things like swaps: • ($a, $b) = ($b, $a);

  12. Arrays • Arrays is a different data type that is created using the @ symbol • For example: @numbers = (1..100); • Accessed with $ before the variable name and [n] right after (n being the index that you want to access in the array) • For example: $numbers[2] • Perl starts these arrays at 0. • Accessing an index that is empty will not crash Perl (Like it did in C++) it will simply return undef (so either 0 or “”)

More Related