Perl Interview
Perl Interview
?
Hello Friends, Who would have time to answer the following questions for
an interview prepration? Answer the one you feel like , I am trying to
collect different answers.
1. What arguments do you frequently use for the Perl
interpreter and w
+hat do they mean?
2. What does the command µuse strict¶ do and why should you
use it?
3. What do the symbols $ @ and % mean when prefixing a c
variable?
4. What elements of the Perl language could you use to
structure your
+code to allow for maximum re-use and maximum readability? c
5. What are the characteristics of a project that is well
suited to Pe
+rl?
c
1. Why do you program in Perl?
2. Explain the difference between my and local.
3. Explain the difference between use and require.
4. What¶s your favorite module and why? c
5. What is a hash?
6. Write a simple (common) regular expression to match an IP
address,
+e-mail address, city-state-zipcode combination.
7. What purpose does each of the following serve: -w,
strict, -T ?
8. What is the difference between for&foreach, exec &
system?
9. Where do you go for Perl help?
10. Name an instance where you used a CPAN module.
11. How do you open a file for writing?
12. How would you replace a char in string and how do you
13. store th
+e number of replacements?
14. When would you not use Perl for a project?
[download]
Thanks
20050404 Unconsidered by Corion: Was considered by gmax: EDIT - remove code tags
and reparent under Interview Questions (edit:20 keep:6 del:2)
Re: Interview Prepration
by cog on Apr 03, 2005 at 20:07 UTC
I'll try... [reply]
[d/l]
What arguments do you frequently use for the Perl [select]
interpreter and what do they mean?
It's not the project that is well suited, it's the language that
might be! And I don't feel confortable yet (with the current
experience I have) answering to that :-) Sorry :-)
Because it's fun and fast (to code). I don't spend loads of
time trying to figure why the code doesn't work when I could
be spending it thinking about how to solve the problem. The
community around it is also a big plus!
I'm not sure but I think I heard someone say it was kind of
the same thing, internally... I may be wrong about this... But
you do get the same effect, apart from some weird case I'm
not thinking about right now...
What is a hash?
Look... that is not a Perl question... but OK, I'll play along...
Think of it as a table with two columns. You put keys in the
left column and their corresponding values in the right one.
And then I should tell you lots of stuff, like "You can't have
a value with a key", "You can't have two values for the same
key" and so on (No, you can't have two values for the same
key, what you can have is a value that holds more stuff
inside it).
x How would you replace a char in string and how do you
$string =~ y/a/b/
!
"
D #
$
$"
$
%&
' ?
$
%
'
Other things are also important... can you rely on the guy to
spend some time with people who need his help? can you
rely on him/her working harder when the deadline [reply]
approaches? Will he/she be a nice person to have around? :-)
But if the applicant for the job knows this regex by heart, I
wouldn't hire him. There must be something very
fundamentally wrong with him/her if he stuffs his brain with
this kind of knowledge.
CountZero
(!
- Conway's Law [reply]
Re^2: Interview Prepration
by Fletch on Apr 04, 2005 at 02:32 UTC
Yeah, but if you ever need to know how many
toothpicks there are or when Judge Wapner is on . . .
($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss')
=~y~b-v~a-z~s; print [reply]
Re: Interview Prepration
by talexb on Apr 04, 2005 at 03:37 UTC
Instead of being horribly methodical, I just thought for my
own amusement I'd answer this post without checking
anything with the reference books. So if there are mistakes, it
has to do with my own faulty memory.
J #
"
x #
"
½ #
)*
+
" [reply]
[d/l]
The dollar sign signifies a scalar, the at sign means an array, [select]
and the % means a hash, also known as an associative array.
( #
!
"
, #
-
"
J #
"
Someone once said that "Perl fits your brain like a glove" --
I'm able to get things done in Perl faster then I ever did using
C or awk, and getting things done is how I earn my salary. In
addition, there's a terrific Perl community available for
questions and support.
x
½
, #
"
. #
% '
!
!
!
/
#
!
!0"
D #
$
$"
J 1
2?1
When I wanted to write a command line utility to log on to a
web application through HTTPS and upload a file, I
used LWP::Simple. This saved me huge amounts of time and
sweat.
JJ 3
"
I use a '>' in the open statement. I also check that the open
succeeded, and if not, the script dies.
Jx 3
Round 1.
1.c #
" Whatever ones
are appropriate and they mean whatperlrun says they
mean.
2.c #
45
" Both an explanation of what it [reply]
does and why it is good may be found atstrict.pm. I [d/l]
refer to it as a typo checker. [select]
3.c #
)*
+
" The way that I think about it is
that $ means "the", @ means "these", and % means
"dereference as a hash". Note that if you are
accessing a single element of an array or a hash then
you use $ for "the" element, and if you take a slice of
an array or a hash then you use @ for "these" items
from the slice.
4.c #
!
" The whole language. I really
hope that you're planning to fail someone who
blathers out, "Its support for object-oriented
programming" because if you think that OO is the
only path to reusability and maintainability, then
you're not very good at either of those.
Round 2.
5.c #
" Because I'm paid and I
enjoy being productive.
6.c
The local operator is misnamed, it really means
something like "temp". It temporarily replaces a
variable with a new variable, and then when you
finally exit your current scope it replaces the old
value. (If you call other functions in other scopes, the
locally set variable is visible.) By contrast my creates
a lexical scope, any references to that variable from
the declaration to the brace that ends your scope
refers to the new lexical variable. To underscore that
the two mechanisms are unrelated, note that it is
possible to use local on variables in hashes and
arrays. The only reason that you cannot use local on
lexical variables is that Larry Wall thinks that that
would be too confusing.
7.c
When you say use Foo qw(bar
baz); you're saying ËEGIN {require Foo; Foo-
>import(qw(bar baz));}. (In an interview I could
explain that further.)
8.c #
5
" There are too
many out there to have a single favorite, but if I had
to name one then it would probably be DBI. In my
work I encounter a lot of databases, and a database
driver/interface is necessary piece that I use all of the
time that I'm glad not to have to write.
9.c #
" A hash is a kind of datastructure for
key/value pairs that makes average time to access a
key, insert a key, or delete a key O(1). If need be I
can explain how they work. They are a native data
type in Perl. In Perl you use %foo to talk about the
whole hash, and $foo{bar} to access one value in
the hash. A coding tip. I like naming my hashes in
such a way that hash lookups can be read "of".
10.c#
% '
!
!
!
/
I would not handle these tasks
with a single regular expression, and I would advise
not hiring anyone who thinks that they can do so.
11.c#
!
!0" They turn on warnings, make Perl less
lenient, and disallow doing dangerous operations
with dangerous data.
12.c#
$
$
" Well for and foreach are synonyms. You're
probably thinking of the difference between the C-
style for (my $i = 0; $i < 10; $i++)
{...} and the clearer Perlish foreach my $i
(0..9) {...}. As for the other two, exec replaces
the current process with another, while system pauses
the current program as it runs another one, then
returns information about whether that program
succeeded.
13.c#
" First perldoc. Then
my library of books. Then co-workers. Then
perlmonks. In that order.
14.c1
2?1
Do I get bonus marks for using my own
CPAN module? :-P
15.c3
" Something like
this: open(my $fh, ">", $file) or die "Cannot
write to '$file': $!"; Note that the error
message matches the recommendations in perlstyle,
and note the use of 3-argument open as discussed
at Two-arg open() considered dangerous.
16.c3
" $string
=~ s/$char/$replacement/g;
17.c3
" my
$count = ($string =~
s/$char/$replacement/g); Note that the parens
are not required, but I think it is clearer with them
included.</code>
18.c#
-" There are
lots of possible reasons not to use Perl. Performance
really is critical. Space really is critical. The project
is to adapt a program written in some other language.
Key developers really hate Perl and the political
battle is not worthwhile. Possible reasons multiply ad
nauseum.
vs @foo[1].
Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is
posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the
public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly
regular basis. If I made a mistake, please let me know (such as by replying to this node).
my = lexical scoping: