http://www.perlmonks.org?node_id=444523


in reply to Interview Prepration

I'll try...

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

Man... I use lots of them!!! I can't explain them all :-) I even gave a talk and wrote an award winning paper on them... But OK, I guess I'd go with -e for one-liners -n and -p for line processing, and probably with -i for inline processing (I would mention -w, but I "use warnings" instead)

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

It enforces strictness! :-) You should use it because it will help you avoid pestering errors that nobody likes (forgotten my declarations being the most usual ones). I nowadays use it most for discipline. It's not that one my programs wouldn't work without it, but I prefer to be on the safe side. Also note that I don't use strict for one-liners.

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

They mean what's after them is supposed to be interpreted, respectively, as a scalar, an array or a hash.

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

Are you refering to modules or am I getting something wrong? Are you talking about objects? Some good practices? I think the question should be rephrased...

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

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 :-)

Second round :-)

1. Why do you program in Perl?

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!

2. Explain the difference between my and local.

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...

3. Explain the difference between use and require.

"use" is at compile time, "require" is at run-time? It's weird how you code and code and only when somebody asks you something you start having questions about it :-)

4. What’s your favorite module and why?

CPAN::Mini, for now I have the CPAN on my laptop and no longer rely on internet access to install new modules. If you asked me for another one, it would be Data::Dumper

5. 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).

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

IP address: qr/(\d{1,3}\.){3}\d{1,3}/ # Yes, it accepts 0's at the beginning and that's probably wrong, but then again, I'm not actually at a job interview :-)

e-mail address: qr/\w+\@\w+\.\w+/ # once again, that's wrong; I would have to check on what's valid and what's not, because I really don't know :-)

city-state-zipcode: Being Portuguese, I really do not know what a city-state-zipcode combination looks like :-\

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

-w uses warnings, strict has already been explained above and -T is tainted mode, which I usually don't use because I don't usually get information I don't trust.

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

for & foreach are now an alias to each other (Ok, one of them is implemented, but they're actually the same thing). As for exec & system, I don't use them much, so I'd have to check on documentation (and don't forget backticks, too)

9. Where do you go for Perl help?

I usually *give* Perl help, but when I need it (because I sometimes do too) I first ask some friends of mine, and then I come to perlmonks.

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

I use CPAN modules on a daily basis :-) I used LWP the other day to retrieve my yml files (kwalitee stuff)

11. How do you open a file for writing?

Usually with open (FILE, ">$file") or die "could not open file '$file' for writing ($!)";

12. How would you replace a char in string and how do you

$string =~ y/a/b/

13. store the number of replacements?

my $number = y/blah/blah/, but that's not really a good question, because many people don't know that, and that doesn't make them worse programmers.

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

When Hell freezes over :-P

Replies are listed 'Best First'.
Re^2: Interview Prepration
by chas (Priest) on Apr 03, 2005 at 20:44 UTC
    "2. Explain the difference between my and local.
    I'm not sure but I think I heard someone say it was kind of the same thing, internally... I
    "
    There is actually a significant difference. "my" creates lexically scoped variables (e.g. existing within a block.) "local" variables have run-time scoping; "local" saves the (previously defined) values of arguments on a stack and later restores them, using the "locally defined" values during some containing scope. Changes made by "local" to global variables can be visible outside the lexical scope of the "local" variables e.g. in nested subroutine calls. I learned about this from the book "Effective Perl Programming" by Joseph Hall, and Randal Schwartz (Addison Wesley Publ.) Highly recommended!
    chas
      I learned about this from the book "Effective Perl Programming"

      I'm in the middle of a bunch of Perl books (I always am).

      Coincidentally, that's one of them :-) Guess I didn't reach that part yet... :-)

        Me too, and I often go back and read over the ones I've read in the past. It's like watching a movie the second time - you pick up things you missed before. I have one of the first versions of "Effective Perl Programming". The discussion about "my" and "local" is in the chapter on subroutines. Along with typeglobs, it seems one of the more subtle less understood notions in Perl. (My understanding is only partial, for sure.)
        chas
Re^2: Interview Prepration
by tilly (Archbishop) on Apr 04, 2005 at 01:49 UTC
    Round 1, question 3, your answer cannot be reconciled with the syntax @foo{'this', 'that'} = qw(whatever fits);
Re^2: Interview Prepration
by merlyn (Sage) on Apr 04, 2005 at 07:17 UTC
      I know what you mean, you are correct, but you can write for or foreach and you will get the same result (and you say that in that link), which was what I was trying to say :-)

      It didn't even occured to me mentioning the two different types of for/foreach because I thought of the question in terms I answered it :-)

      Uh, yes. The words for & foreach are an alias to each other.
        Right. They're syntax aliases, but they're semantically entirely different things. Did you read what I quoted? It explains what I mean, and I don't want to keep retyping that.

        -- Randal L. Schwartz, Perl hacker
        Be sure to read my standard disclaimer if this is a reply.

Re^2: Interview Prepration
by jhourcle (Prior) on Apr 04, 2005 at 03:17 UTC

    3. Explain the difference between use and require.

    "use" is at compile time, "require" is at run-time? It's weird how you code and code and only when somebody asks you something you start having questions about it :

    use also calls import(). From use:

    Imports some semantics into the current package from the named module, generally by aliasing certain subroutine or variable names into your package. It is exactly equivalent to

    BEGIN { require Module; import Module LIST; }

    -

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

    for & foreach are now an alias to each other (Ok, one of them is implemented, but they're actually the same thing). As for exec & system, I don't use them much, so I'd have to check on documentation (and don't forget backticks, too)

    for can be used as an alias for foreach, and visa-versa. But please, please don't use foreach with a C style for loop:

    foreach ( loop_init(); exit_test(); increment() ) { ... }

    As for exec and system, one of 'em forks, one doesn't. I always forgot which one is which, and look them up, too. (exec never returns, while system does) and sometimes, I just open a pipeline.

Re^2: Interview Prepration
by zentara (Archbishop) on Apr 04, 2005 at 16:17 UTC
    "use" is at compile time, "require" is at run-time? It's weird how you code and code and only when somebody asks you something you start having questions about it :-)

    I'm a big believer in the saying: "The way to learn something, is to teach it".

    We ( I at least ) seem to have this "active" and "passive" code knowledge; much like an "active and passive" vocabulary. You don't really get to a real understanding of it, until you have to explain it to someone else ( who is asking WHY? alot ) :-).


    I'm not really a human, but I play one on earth. flash japh