Section 1

Preview this deck

Explain the @ARGV array 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

6 years ago

Date created

Mar 1, 2020

Cards (62)

Section 1

(50 cards)

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

Explain common hash functions

Front

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

Back

Identify the variable that provides the last index of an array

Front

$#arrayName

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

Define the open() statement in perl

Front

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

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

Identify the four types of loops in perl

Front

while until for foreach

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

Identify the use of comments in perl

Front

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

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

unshift(@array, $newValue)

Front

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

Back

List the conditions which evaluate as false

Front

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

Back

shift(@array)

Front

Removes the first element of the array

Back

Identify how to include modules in perl

Front

use moduleName; Ex: use Roman;

Back

reverse(@array)

Front

reverse the elements of the array

Back

push(@array, $newValue)

Front

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

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

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

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

What does $#arrayName return

Front

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

Back

keys(%hash)

Front

returns all of the keys of the hash as an array

Back

Explain assignment of a hash variable for a single hash element

Front

$hashName{keyName}="Value to Add"

Back

What does scalar(@arrayName) return

Front

The size of the array names @arrayName

Back

Explain common array functions

Front

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

Back

delete($hashName{key})

Front

delete the hash entry with the key given

Back

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

Front

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

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

Describe hash variables in perl

Front

- An associative array

Back

Describe scalar variables in perl

Front

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

Back

Explaing assignment of scalar variables in perl

Front

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

Back

Explain how to write to a filehandle

Front

print(FILEHANDLE "Data to output
");

Back

values(%hash)

Front

returns all of the values of the hash as an array

Back

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

Front

> write >> append < read

Back

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

Front

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

Back

Interpret the syntax of a while loop

Front

while(condition) { CODE TO EXECUTE }

Back

Identify the two phases of creating a PERL program

Front

1. Editing 2. Execution

Back

sort(@array)

Front

Sort and array alphabetically

Back

Define the two primary methods of executing system commands in perl

Front

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

Back

Summarize the siz arithmetic comparison operators

Front

< > == <= >= !=

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

exists($hashName{keyName})

Front

does the hash key with "keyName" exists

Back

chomp($string)

Front

remove trailing newline

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

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

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

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

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

pop(@array)

Front

Removes the last element from the array

Back

Summarize the size string comparison operators

Front

eq ne lt le gt ge

Back

Section 2

(12 cards)

lc($string)

Front

returns a copy of the string as all lower case

Back

split(/\s/, $string)

Front

split string into an array using spaces as delimeter

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

join(':', @array)

Front

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

Back

ucfirst($string)

Front

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

Back

Regular Expression chararcter classes

Front

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

Back

Regular Expression Quantifiers

Front

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

Back

lcfirst($string)

Front

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

Back

Two basic binding operators in regular expressions

Front

=~ Contains !~ Does not contain

Back

chomp(@string)

Front

remove trailing newline from each element in the array

Back

length($string)

Front

returns the length of the string including escape sequences

Back