Section 1

Preview this deck

Identify the four types of loops in perl

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

4 years ago

Date created

Mar 1, 2020

Cards (62)

Section 1

(50 cards)

Identify the four types of loops in perl

Front

while until for foreach

Back

What does $#arrayName return

Front

The value of the last index of the array (NOT the data stored in that array element)

Back

Identify the use of comments in perl

Front

- Documenting code - Created by placing a "#" on a line. - Comments are not multi-line

Back

Explain assignment of hash variables in perl (when oringally defining the hash)

Front

%hashname = (key1=>"value1", key2=>"value2", key3=>"Value3")

Back

Identify the variable that provides the last index of an array

Front

$#arrayName

Back

List the three basic file access modes of the open() function

Front

> write >> append < read

Back

Identify the two phases of creating a PERL program

Front

1. Editing 2. Execution

Back

Describe scalar variables in perl

Front

- Singular variable, starts with "$" - Number, characer or string - Perl does automatic type conversion of scalar variables

Back

Summarize the size string comparison operators

Front

eq ne lt le gt ge

Back

shift(@array)

Front

Removes the first element of the array

Back

chomp($string)

Front

remove trailing newline

Back

What does scalar(@arrayName) return

Front

The size of the array names @arrayName

Back

Explain the @ARGV array in perl

Front

A special system variable used to pass arguments to script - Ex: perl ./myScript.pl arg1 arg2 --$ARGV[0] will be "arg1", $ARGV[1] will be "arg2"

Back

Describe the command substitution in perl

Front

- uses grave marks `command args` - returns the output of the command to the variable you specify - if $output = `command arg` the output is stored all in one variable (all lines seperated by
) - if @output = `command arg` the output is stored with each line of the output as a different array element

Back

Explain the use of "if" "if-else" and "if-elsif-else"

Front

flow-control There are also unless conditional flow-control statements

Back

Identify the interpreters role in handling syntax errors

Front

- In perl, the interpreter will recognize syntax errors and halt execution BEFORE it begins - Interpreter will output statements; it does not understand and the line which it encountered the error on

Back

Explain the assignment of arrays in perl

Front

@array=("el1", "el2", "el3", 16, 12); - Elements need not be similar data types - Arrays can be assigned or read in scalar context (Ex: $myArray[4] = 2) - Special array $#arrayName give value of last index available in the array. Ex an array of size 5 will have its $#arrayName = 4 - scalar(@arrayName) returns the size of the array

Back

Explain common array functions

Front

pop(@array) push(@array, $new Value) shift(@array) unshift(@array, $newValue) sort(@array) reverse(@array)

Back

Define the two primary methods of executing system commands in perl

Front

- system("command args") - `command args`

Back

sort(@array)

Front

Sort and array alphabetically

Back

Summarize the siz arithmetic comparison operators

Front

< > == <= >= !=

Back

Interpret the syntax of a while loop

Front

while(condition) { CODE TO EXECUTE }

Back

Explain assignment of a hash variable for a single hash element

Front

$hashName{keyName}="Value to Add"

Back

List the conditions which evaluate as false

Front

0 undef () -- arrays "" -- string EOF -- end of file "0"

Back

Define common string manipulation functions

Front

substr($string, $start, $numchars); length($string) lc($string) uc($string) chomp($string) chomp(@string) join(':", @string) split(/\s/, $string) lcfirst($string) ucfirst($string)

Back

values(%hash)

Front

returns all of the values of the hash as an array

Back

Explaing assignment of scalar variables in perl

Front

- Assigned using "=" - Ex: $myVariable = 5;

Back

Describe hash variables in perl

Front

- An associative array

Back

reverse(%hashName)

Front

swap keys for values and values for keys. Will cause issues if there are multiple hash entries with the same value

Back

Explain how to read an entire file into an array (one line per element)

Front

@entireFile=<FILEHANDLE> Again you could chomp this array to get rid of all the newlines (Ex chomp(@entireFile)

Back

keys(%hash)

Front

returns all of the keys of the hash as an array

Back

Define the open() statement in perl

Front

open(FILEHANDLE, file_mode, "filename.txt") - file mode is either ">", "<" or ">>"; write, read and append respectively

Back

unshift(@array, $newValue)

Front

Add a new element to the from of the array with the value $newwValue

Back

reverse(@array)

Front

reverse the elements of the array

Back

Explain common hash functions

Front

keys(%hash) values(%hash) each(%hash) delete($hash{keyName}) exists($hash{keyName}) reverse(%hash)

Back

delete($hashName{key})

Front

delete the hash entry with the key given

Back

Explain variable context in perl

Front

- can be scalar, array, or hash context - tells the interpreter what you are looking for (Ex: "$arrayname[$index_number]")

Back

exists($hashName{keyName})

Front

does the hash key with "keyName" exists

Back

Identify the purpose of {} in an "if" statement

Front

Define the execution block of the if statement. Unlike C, the {} braces ARE REQUIRED

Back

Explain how to write to a filehandle

Front

print(FILEHANDLE "Data to output
");

Back

Describe array variables in perl

Front

- A collection of data (static data, scalar variables, arrays or hashes can all be stored in an array element)

Back

Identify how to include modules in perl

Front

use moduleName; Ex: use Roman;

Back

each(%hash)

Front

returns a two element ray of the next key value pair; resultArray[0] is the key resultArray[1] is the value

Back

push(@array, $newValue)

Front

Adds a new element to end of the array with value $newValue

Back

pop(@array)

Front

Removes the last element from the array

Back

Describe the system() function in perl

Front

- used to execute an external command -will output results of command to terminal - returns the exit status of the program that ran - use this for commands that you dont care about SAVING the output to a variable

Back

Identify what modules are in perl

Front

- Synonymous with header files in C - Collection of like functions and variables that may be used in your program

Back

Explain the %ENV hash array

Front

Stores information about the current users environment. You can print this from the command line using printenv

Back

Interpret the syntax of the foreach loop

Front

foreach $element(@arrayName) { CODE TO EXECUTE } In this case $element is a reference to a specific element of @arrayName. If you change the value of $element, the value will change in the array as well

Back

Explain how to read a line from a file handle

Front

$line=<FILEHANDLE> To get rid of the newline in $line, you could now chomp() (Ex: chomp($line);)

Back

Section 2

(12 cards)

join(':', @array)

Front

join the elements of the array seperating the elements with the ':' character

Back

split(/\s/, $string)

Front

split string into an array using spaces as delimeter

Back

Two basic binding operators in regular expressions

Front

=~ Contains !~ Does not contain

Back

uc($string)

Front

returns a copy of the string as all upper case

Back

substr($string, $startindex, $numchars)

Front

return the sub string starting at index $startindex and ending after $numchars chars in the string $string

Back

ucfirst($string)

Front

returns a copy of the string with the first letter upper case

Back

length($string)

Front

returns the length of the string including escape sequences

Back

lcfirst($string)

Front

returns a copy of the string with the first letter lower case

Back

Regular Expression Quantifiers

Front

* - 0 or more characters + - 1 or more characters ? - 0 or 1 characters

Back

lc($string)

Front

returns a copy of the string as all lower case

Back

chomp(@string)

Front

remove trailing newline from each element in the array

Back

Regular Expression chararcter classes

Front

\w - alphanumeric word including underscor \d - digits 0-9 \s any whitespace . - any character

Back