• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/54

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

54 Cards in this Set

  • Front
  • Back
how can you check the version of perl?
perl -v
What is a package for?
Packages allow you to define a distinct namespace for a given block of code. A namespace is a table of variable names.
Why use namespaces?
organize code ensure reusability prevent errors if an identifier is overwritten
What does the package keyword do?
Package keyword assigns the current package
Where can you use the package keyword at in a perl script?
Anywhere
How are packages organized inside a file
1 file=1 package or ??
How would you write a package statement
#!/bin/perl -w .... not part of package package Elephant; $myString = "The elephant" ... all other lines are part of package Elephant package Fox; $myString = "The fox" $myString variable has two different values depending on what package is used Fox or Elephant
Where are all Perl symbols such as variables
file handles
How do you access the $myString variable item in a symbol table for the Elephant package? How about for the default package?
%Elephant::myString - Elephant package and $myString package Elephant; $myString = "The slow elephant"; package main; print $Elephant::myString;
How do you nest a Fox package after an Animal package
package Animal; ..... package Animal::Fox; #use colons to make a nested package $myString = "The fox"; package Animal::Elephant; #now nested inside another package package main; print $Animal::Elephant::myString
What is the purpose of BEGIN and END block statements?
The BEGIN is executed first before rest of script and END? #!C:perl\bin\perl.exe END { print("Gamma\n");} #executed last print ("we are playing\n"); #this is where it goes... BEGIN { print("start here\n");} #executed first
What are modules? What are they for?
Distinct Perl scripts with a .pm ending. foo.pm or help.pm They must have a package other than main.... Perl modules help reuse software
How do you use a module in another Perl script?
The use and require statement.
What do modules have in them?
Subroutines and variables?
What does the require statement do? require Foo;
The require:Foo means that you want to include the Foo module and all the functionality in there.
How does file search for Perl Modules from the required modules?
The require keyword triggers Perl to search for the Perl module in the local directory and the @INC array path (include path).
How do you use the SolveSub subroutine in the Perl module Foo and include the module in your program.
require Foo; print Foo::SubSolve("10 0.5 * -2");
What is the use statement for? use Foo("solve"); or use Foo ("solve"
"\?token");
Can you use the "use" statement to select only specific subroutines to export? use Foo ("solve"
"\$token); will this be allowed?
What is the difference between the require statement and the use statement?
use statements look for modules during compilation then loads the module and runs code before compiling the rest of the file?
What is in a Perl Module (.pm file)?
Perl modules have a package and several supporting subroutines
What does the perl -w switch enable?
#NAME?
How do you activate the -w switch?
#!\usr\bin\perl -w (put the -w in the first line)
How can you use the print command to help with debugging?
Use print at specific checkpoints: print("Checkpoint 2\n"); ...... print("Checkpoint 3\n");
what does the strict module do to help debug perl programs?
Requires that all variables be declared before they are used.
How does the strict module require you to declare references
variables
How can you use the strict module to restrict only subroutines need to be declared before use but allow undeclared variables?
use strict 'subs'; no strict 'variables';
What is the my() funtion for?
Allows you to declare your variables ahead of time.
How can you run the Perl Debugger
use perl -d prog.pl
What can you do with the debugger?
Examine source code set breakpoints display function stack check variables change variables
Can you use the debugger to detect compile time errors?
Perl debuggers can only check during run time
While in the debugger how can you single step through the card?
Press the s-key
What are some of the Perl debugger commands?
L - lists all breakpoints b sets a breakpoint at current execution line d =deletes a break break D deletes all breakpoints c-continue p-prints out breakpoint V main (list variables)
The assignment operator is: ?
=
A scalar variable is what? what does it start with?
a single value like string or number It always starts with $
what are the binary operators for add
subtract
What are the perl unary operators
#NAME?
Why do we have operators in perl and what are the three types?
(i.e. binary
What is a string variable?
A scalar variable that stores a string?
How do you set the scalar variable $joe to the stirng value: Joe Baby
$joe="Joe Baby";
What is <STDIN>?
A special data type known as a list
What happens when the perl interpreter sees the <STDIN> on a line?
It waits for the user to respond with a character sequence of data and presses the Enter key.
When a user inputs a line of text into <STDIN> what gets brought with it in addition to the character?
The perl interpreter automatically retrieves the newline character as well \n.
How can you get rid of the new line character at the end of a string? $age = <STDIN>; actually received "30\n" not "30" so need to get rid of the \n in this case.
chomp($age)
What is a Perl Package end with?
Ends with a 1: to show the module completed successfully.
What is the our keyword for?
The our keyword declares a variable to be global to the module.
Is <STDIN> a file handle or a special variable?
A filehandle
How do you display Executing your script to the user when your program starts?
print ("Executing your script\n");
What is the numeric boolean operator for not equal to?
!=
What is the numeric boolean operator for equal to?
==
what is returned from this boolean expression $a = 100; $b = 150; print $a == $b;
Nothing is returned
what is returned from this boolean expression $a = 100; $b = 100; print $a == $b;
Since the value is TRUE
What are the different types of boolean operators?
< <= > >= == !=