Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Interview Prepration

by talexb (Chancellor)
on Apr 04, 2005 at 03:37 UTC ( [id://444577]=note: print w/replies, xml ) Need Help??


in reply to Interview Prepration

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.

And in any case, a code sample should prove most of these interview questions moot.

    1. What arguments do you frequently use for the Perl interpreter and what do they mean?

I use -w to turn warnings on, and I use -c to compile code. I also use -d to invoke the debugger. I never use perl without arguments. That's like driving a car without a seatbelt, or riding a motorcycle without a helmet.

    2. What does the command use strict do and why should you use it?

use strict tells the Perl compiler to be a little pickier about certain syntactical checking. It's almost never a poor choice.

    3. What do the symbols $ @ and % mean when prefixing a variable?

The dollar sign signifies a scalar, the at sign means an array, and the % means a hash, also known as an associative array.

    4. What elements of the Perl language could you use to structure your code to allow for maximum re-use and maximum readability?

I'm afraid I don't understand the question. I already use Perl for 95% of my programming, with the reminder in some shell scripting. (I didn't include SQL answering this question, since it's not procedural when I use it.)

Structuring code has nothing to do with Perl, anyway. It's basic software craftmanship.

    5. What are the characteristics of a project that is well suited to Perl?

Perl is useful when you want to be able to leverage the work of thousands of other dedicated, excellent programmers available through CPAN modules, when you want to be able to rapidly prototype, when you want to avoid paying exorbitant prices for 'development environments', when you want to avoid idiotic vendor limitations, useless support and incomprehensible documentation.

    1. Why do you program in Perl?

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.

    2. Explain the difference between my and local.

my Creates a new lexical in the current scope; if there is an existing variable with the same name, you'll get a warning. local does the same thing but 'pushes' the original value (if it exists) into the background until the current scope is exhausted.

    3. Explain the difference between use and require.

use brings the code in at compile time, where rqeuire pulls the code in at run time.

    4. Whats your favorite module and why?

I don't really have favourite module -- the one that handles file names and directories is handy, File Special Functions or something like that.

    5. What is a hash?

A hash is an unordered associative array, which means it's a variable that contains multiple elements, where each element is accessed by an associated key, rather than by an offset (like in an array).

    6. Write a simple (common) regular expression to match an IP address, e-mail address, city-state-zipcode combination.

This question is vague, and I don't have time to prove why.

    7. What purpose does each of the following serve: -w, strict, -T ?

You already asked about -w -- that's Perl's command line option for warnings. You already asken about strict -- you use strict when you want the perl compiler to do additional syntax checking. The -T command line switch turns on taint checking, something that's useful for CGIs when you want to make sure there's no user input that can possibly flow through to the operating system for security reasons. Typically you want to enable taint-checking as early in the command line options as possible.

    8. What is the difference between for & foreach, exec & system?

for in Perl is like a for loop in C; foreach iterates over a list. exec calls an external program, never to return, where system calls the external program and returns.

    9. Where do you go for Perl help?

I look in perldoc, in the various O'Reilly books that I have, and finally I visit Perl Monks.

    10. Name an instance where you used a CPAN module.

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.

    11. How do you open a file for writing?

I use a '>' in the open statement. I also check that the open succeeded, and if not, the script dies.

    12. How would you replace a char in string and

I could use s/// or tr/// to replace a character in a string, but it depends on the situation.

    .. how do you 13. store the number of replacements?

I think tr/// returns the number of replacements, but I'd have to check.

    14. When would you not use Perl for a project?

When either shell scripting will do the job, or when performance is paramount in which case I'd look at C. There may also be other external factors.

Alex / talexb / Toronto

"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-03-28 11:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found