Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Interview Prepration

by tilly (Archbishop)
on Apr 04, 2005 at 03:48 UTC ( #444579=note: print w/replies, xml ) Need Help??


in reply to Interview Prepration

Answers to these are not going to help you. But I'll fire these off since I'm feeling bored.

Round 1.

  1. What arguments do you frequently use for the Perl interpreter and what do they mean? Whatever ones are appropriate and they mean what perlrun says they mean.
  2. What does the command ‘use strict’ do and why should you use it? Both an explanation of what it does and why it is good may be found at strict.pm. I refer to it as a typo checker.
  3. What do the symbols $ @ and % mean when prefixing a variable? 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. What elements of the Perl language could you use to structure your code to allow for maximum re-use and maximum readability? 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.
  1. Why do you program in Perl? Because I'm paid and I enjoy being productive.
  2. Explain the difference between my and local. 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.
  3. Explain the difference between use and require. When you say use Foo qw(bar baz); you're saying BEGIN {require Foo; Foo->import(qw(bar baz));}. (In an interview I could explain that further.)
  4. What’s your favorite module and why? 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.
  5. What is a hash? 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".
  6. Write a simple (common) regular expression to match an IP address, e-mail address, city-state-zipcode combination. 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.
  7. What purpose does each of the following serve: -w, strict, -T ? They turn on warnings, make Perl less lenient, and disallow doing dangerous operations with dangerous data.
  8. What is the difference between for & foreach, exec & system? 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.
  9. Where do you go for Perl help? First perldoc. Then my library of books. Then co-workers. Then perlmonks. In that order.
  10. Name an instance where you used a CPAN module. Do I get bonus marks for using my own CPAN module? :-P
  11. How do you open a file for writing? 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.
  12. How would you replace a char in string? $string =~ s/$char/$replacement/g;
  13. How do you store the number of replacements? my $count = ($string =~ s/$char/$replacement/g); Note that the parens are not required, but I think it is clearer with them included.</code>
  14. When would you not use Perl for a project? 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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://444579]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2020-10-20 07:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (209 votes). Check out past polls.

    Notices?