|Perl Monk, Perl Meditation|
Re: Interview Preprationby talexb (Canon)
|on Apr 04, 2005 at 03:37 UTC||Need Help??|
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.
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.
use strict tells the Perl compiler to be a little pickier about certain syntactical checking. It's almost never a poor choice.
The dollar sign signifies a scalar, the at sign means an array, and the % means a hash, also known as an associative array.
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.
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.
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.
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.
use brings the code in at compile time, where rqeuire pulls the code in at run time.
I don't really have favourite module -- the one that handles file names and directories is handy, File Special Functions or something like that.
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).
This question is vague, and I don't have time to prove why.
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.
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.
I look in perldoc, in the various O'Reilly books that I have, and finally I visit Perl Monks.
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.
I use a '>' in the open statement. I also check that the open succeeded, and if not, the script dies.
I could use s/// or tr/// to replace a character in a string, but it depends on the situation.
I think tr/// returns the number of replacements, but I'd have to check.
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