Chapter 36. The Perl Wizard’s Quiz
Answers are at the end of the article.
What value is returned by a lone
returnstatement?The empty list value
().The undefined value in scalar context, and the empty list value
()in list context.The result of the last evaluated expression in that subroutine’s block.
The undefined value.
What’s the difference between
/^Foo/sand/^Foo/?The first would allow the match to cross newline boundaries.
The first would match
Fooother than at the start of the record if the previous match were/^Foo/gcm, new in the 5.004 release.The second would match
Fooother than at the start of the record if$*were set.There is no difference because
/sonly affects whether dot can match newline.
What does
length(%HASH)produce if you have 37 random keys in a newly created hash?5
37
74
2
What does
readreturn at end of file?0
“0 but true”
“\0”
undef
How do you produce a reference to a list?
[ @array ]\($s, @a, %h, &c)You can’t produce a reference to a list.
\@array
Why aren’t Perl’s patterns regular expressions?
Because Perl allows both minimal matching and maximal matching in the same pattern.
Because Perl uses a non-deterministic finite automaton rather than a deterministic finite automaton.
Because Perl patterns can have look-ahead assertions and negations.
Because Perl patterns have backreferences.
Why doesn’t Perl have overloaded functions?
Because you can inspect the argument count, return context, and object types all by yourself.
It does, along with overloaded operators ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access