New

Long-Term Learning

Learn efficiently and remember over time.

Start Long-Term Learning

Get personalized study reminders at intervals optimized for better retention.
Track your progress on this set by creating a folder
Or add to an existing folder

Add this set to a folder

  • PERL

    - Practical Extraction and Report Language
    - allows easy manipulation of files
    - process text information

    Why PERL?

    - Free
    - Easier to learn than C
    - Does not require a special compiler (Interpretive, not compiled)

    Advantage of PERL

    - Easy to run
    - Efficient in processing biological seq data

    Disadvantage of PERL

    - Generally slower than a compiled program

    Create Perl Program

    - File name with suffix.pl
    - Text editor such as Windows Notepad/ UltraEdit

    Initiate Perl

    - Input e.g. "perl myprogram.pl" under DOS or Unix

    PERL syntax (how words are put tgt)

    - Comments begin with (#).
    Eg # I'm a comment
    - Statements must end with (;)
    Eg print ("I am learning Perl.\n");

    Scalar Data

    - Scalar variable begins with ($)
    - Any combination of letters, numbers, underscores
    Eg $name = "Bob"; #assignment of variable- name
    Eg $number = 123; assignment of variable- number

    Array Data

    - Arrays of scalar denoted with (@)
    - index always start at 0
    Eg @array = (1,2,3);

    Eg
    @students = ("Bob", "John", "Mary");
    (if we want Mary)
    print ("$students[2]\n");

    Arithmetic
    $a + $b

    Sum of $a and $b

    Arithmetic
    $a - $b

    Difference of $a and $b

    Arithmetic
    $a * $b

    Product of $a times $b

    Arithmetic
    $a / $b

    Quotient of $a divided by $b

    Arithmetic
    $a % $b

    Remainder of $a divided by $b

    Assignment
    $var = 5

    assign 5 to $var

    Assignment
    $var++

    increment $var by 1 and assign to $var
    (equal to $var+1 then run program again)

    Assignment
    $var--

    decrement $var by 1 and assign to $var

    Assignment
    $var += 3

    increase $var by 3 and assign to $var

    Assignment
    $var -= 2

    decrease $var by 2 and assign to $var

    Logical
    CONDITION1 && CONDITION2

    True if both CONDITION1 and CONDITION2 are true

    Logical
    CONDITION1 || CONDITION2

    True if CONDITION1 is true or CONDITION2 is true

    Logical
    ! CONDITION

    True if CONDITION is not true

    Relational Operators

    - Check if the ouput is true/ not true

    $str eq "Word"

    Equal to

    $str *ne "Word"

    Not equal to

    $var > 10

    Greater than 10

    $var >= 10

    Greater than or equal to

    $var < 10

    Less than

    var <= 10

    Less than or equal to

    \n

    Newline

    \s

    All white spaces

    $a =~ /pat/

    True if $a contains pattern "pat"

    $a !~ /pat/

    True if $a does not contain pattern "pat"

    $a =~s/hate/love/

    Replace occurences of 'hate' with 'love' in $a

    If ($colour eq "red") {print ("C1\n");}

    # If $colour = red, print as C1

    elsif ($colour eq "green") {print ("C2\n");}

    # If not, $colour = green, print as C2

    else {print ("C4\n");}

    # If not, print C3

    While loop
    $first var = 1;
    while ($firstVar <=10) {firstVar++};
    print ("outside:firstVar = $firstVar\n");

    Program prints:
    outside: firstVar = 11

    For loop
    $sum = 0;
    for ($i=0; $i<=100; $i++) { $sum = $sum + $i; } print ("Sum = $sum\n");

    $i=0; = CONDITION1 = set initial value of loop
    $i<=100; = CONDITION2 = decide is loop continue/stop
    $i++ = CONDITION3 = update loop variable

    chop()
    chop ($var)

    chops off the last character of $var

    print()
    print ($var)

    prints the value of $var to screen

    scalar()
    @array = (0,1,2,3,4);
    $number = scalar (@array);
    print ("Array Size = $number\n");

    Array Size = 5

    scalar() determines size of array

    File Handling
    open()
    open(FILEHANDLE, "test.txt")
    open(FILEHANDLE, ">test.txt")

    open(FILEHANDLE, "test.txt")
    - opens a file and link it to FILEHANDLE for reading

    open(FILEHANDLE, ">test.txt")
    - opens a file and link it to FILEHANDLE for writing to the file.

    $var = <FILEHANDLE>;

    # read one line from the file
    Eg $line=<INFILE>;

    close()
    close (FILEHANDLE)
    Eg close (INFILE);

    Close the file associated with FILEHANDLE

    split()
    split(/pattern/, $variable)
    Eg.
    #!/usr/local/bin/perl;
    $str = "1+3+6+4+5";
    @num = split(/\+/, $str);
    $count = scalar(@num);
    print ("The array has $count elements\n");
    print ("The second element of the array is $num[1]\n");

    - return an array constructed by using the pattern as a delimiter to distinguish elements in $variable

    prints:
    The array has 5 elements
    The second element of the array is 3

    Last statement
    last;

    exits the most inner loop

    $_

    Stores the last thing read by Perl. It is the default variable for many functions.

    $0

    Stores command that ran the current script.

    $!

    Stores error messages returned from OS.

    $^O

    Stores the name of the OS.

    @_

    Stores all arguments passed to a subroutine.

    @ARGV

    Stores all command line arguments

    $#array

    Tells you the index of the last element of an array.

    my

    Makes a local variable.

    The defined function

    Returns false if the variable name has not been defined, and true if the variable name has been defined.

    chomp($name=<STDIN>)

    reads data into a variable and strips the ending character if it is a newline character.

    cut($name=<STDIN>)

    reads data into a variable and strips the ending character no matter what it is.

    What is a single quoted string.

    A literal string that prints exactly what it shows.

    What is a double quoted string

    A string that will replace variable names with their values.

    What are back-quotes

    back quotes allow us to capture the return of a command by placing the command inside the series of back-quotes.

    what is the symbol for the concatenation operator

    .

    in relation expressions what does //i mean

    Case insensitive match

    in regular expressions what does //g mean

    Global; match as many times as possible within the string.

    in regular expressions what does the s/// do

    It is the substitution operator, the string to be matched goes between the first set of slashes and the value to replace it with goes in the second string.

    what is the symbol for any digit character when using regular expressions

    [0-9], \d

    what is the symbol for any word character when using regular expressions

    [A-Za-z0-9_], \w

    what is the symbol for any white space character when using regular expressions

    [\t \r\n\f], \s

    what is the symbol for any non digit character when using regular expressions

    [^0-9], \D

    what is the symbol for any non-word character when using regular expressions

    [^A-Za-z0-9_], \W

    what is the symbol for any non-whitespace character when using regular expressions

    [^\t \r\n\f],\S

    what symbol is the {} in regards regular expressions

    It is quantifier and specifies how elements we are looking for of a said character.

    what does the symbol * mean in regular expressions

    Zero or more of the previous token

    What does the symbol + mean in regular expressions

    One or more of the previous token

    What does the symbol ? mean in regular expressions

    Zero or one of the previous token

    What does the symbol ^ mean in regular expressions

    Start of a string anchor

    What does the symbol $ mean in regular expressions

    End of a string anchor

    What does the symbol \b mean in regular expressions

    Word boundary anchor

    In regular expressions what does the symbol . mean

    match any single character

    What does the symbol () mean in regular expressions

    Group, which is used to make a group of tokens that can be quantified as a unit

    What does a string with the following evaluate to '0' or ''

    false

    What does a string with the following evaluate to '00'

    true

    Please allow access to your computer’s microphone to use Voice Recording.

    Having trouble? Click here for help.

    We can’t access your microphone!

    Click the icon above to update your browser permissions above and try again

    Example:

    Reload the page to try again!

    Reload

    Press Cmd-0 to reset your zoom

    Press Ctrl-0 to reset your zoom

    It looks like your browser might be zoomed in or out. Your browser needs to be zoomed to a normal size to record audio.

    Please upgrade Flash or install Chrome
    to use Voice Recording.

    For more help, see our troubleshooting page.

    Your microphone is muted

    For help fixing this issue, see this FAQ.

    Star this term

    You can study starred terms together

    NEW! Voice Recording

    This is a Plus feature