CT320: Network and System Administration

Fall 2019

IQ 08

CT320 IQ 08

Show Main.IQ08 as a slide show.

Sigils

In Perl, which sigil indicates an array?

  1. @
  2. $
  3. %
  4. #
  5. &
  6. I don't know what the @$%#& a “sigil” is!

@ = array. Think of @ as the a in array.

Declaration

In Perl, how do I declare a scalar?

  1. my zot;
  2. int zot;
  3. my $zot;
  4. int $zot;
  5. You can’t.

We don’t give types to our variables, so int is out. A scalar always has a $ with it.

Arguments

In Perl, how are arguments passed to a function?

  1. sub foo(alpha, beta, gamma)
  2. sub foo($alpha, $beta, $gamma)
  3. Implicitly, in @_.
  4. Via some other agreed-upon global array.

Arguments are passed in @_. Named parameters ($alpha, $beta) are possible, but they’re an experimental feature that you have to explicitly enable.

$_

In Perl, what does $_ mean?

  1. It’s just a scalar with an odd name.
  2. It’s related to @_ somehow.
  3. Sometimes, implicitly set in a for loop.
  4. Sometimes, implicitly set in a while loop.

$_ is a scalar with an odd name, but not “just” that. It’s implicitly set in for (1..3), and in while (<FH>) loops.

Array

In Perl, how do I concatenate @a and @b into @c?

  1. @c = @a + @b;
  2. @c = (@a, @b);
  3. @c = @ab;
  4. @c = @a, @b;
  5. @c = @a; push @c, @b;

A does addition, in scalar context, of the sizes of @a and @b. @ab is a brand-new variable. Either B or E will work, but B is easier to read.

What will this code display?

if ("My dog has fleas" =~ /(d*g)/) {
    print "I matched “$1”\n";
}
else {
    print "nope\n";
}
I matched “g”
  1. I matched “nope”
  2. I matched “dog”
  3. I matched “g”
  4. It will throw an exception.
  5. nope

Sycophancy

What is the best language ever?

  1. Perl
  2. Perl
  3. Perl
  4. Perl
  5. Perl
  6. Python