http://qs321.pair.com?node_id=444621


in reply to Interview Prepration

  1. Seldomly when using a she-bang line (-T being an exception, and for quick and dirty hacking, -s), but from the command-line: -w, -p, -n, -a, -i, -l, -e, -0, -c, -D, -v, -V, -I, -M, -x belong to my favourites. Do I have the time to explain all of them?
  2. use strict is not a command - it's a statement. It compiles the strict.pm module, and calls the import sub in it. This will twiddle some bits in $^H, which causes the compiler to check for certain things, and complain if the conditions aren't met. I don't know whether I should use it, but I can explain why I often do use it. (insert strictness mantra).
  3. It depends a little on the context. It could mean the following variable are scalars, arrays or hashes, but it could also mean that the following expression is used as a scalar, list, array or hash.
  4. All of them. But perhaps "whitespace" is the most important for readability (and hence, reusability). Although, technically, "whitespace" would mean the absence of any element of the Perl language.
  5. I believe that "suitable language" is more defined by the programmers going to do the project than the project itself most of the time, so my answer would be "if the programmers are Perl programmers".
  1. Because I happen to know it, and it often satisfies my needs.
  2. my declares a lexical variable (or a set of lexical variables), local creates a new (or a set of new) value for a non-lexical variable (which is not the same as a package variable).
  3. use is done at compile time, calls import if applicable, and can only be given a bare word as first argument. require is done at run-time, takes an expression (or a version) as argument, and doesn't call import.
  4. It depends on what I want to do.
  5. A mapping that maps strings to arbitrary scalars.
  6. IP addresses? In which format? Dotted quads? Hex? 32 bit integers? IPv4? IPv6? There are no simple regexes for e-mail addresses, unless you either wants lots of false positives, false negatives, or both. City-state-zipcode of which country? US? If so, what format zip codes? 5 digits? 5+4? Either? As for states, 2 letter states? 3 letter states? 2 or 3 letter states? Do you expect your programmers to remember all 50 abbreviations? There are a few extra areas that have "state codes" as well? Am I supposed to know them?
  7. -w tests whether a file (or filehandle) is writeable for the EUID, -T guesses if a file (or filehandle) is an ASCII file, and strict is a bare word that "use strict;" wouldn't approve off.
  8. There's no difference between for and foreach. And system does a fork, execs in the child, waits in the parent.
  9. The manual has all I need.
  10. You see, I wanted to write this program ....
  11. It depends. There's 2-arg open, 3-arg open, sysopen (either of which can be used with a filehandle, or a reference to a filehandle as first argument, and Perl will happely autovivify an undefined value into a reference to a filehandle for you as well), and modules like IO::File, IO::All, and Inline::Files. I typically use 2-arg open, 3-arg open and sometimes sysopen. All three with references to filehandles (usually autovivified handles) as first argument. Filehandles as first argument is asking for trouble.
  12. _A_ character in a string? As in, a single one? Say, the third character? substr($str, 2, 1, "x") if length($str) >= 3;
  13. Well, that would be either 0 or 1, and it will be 1 if, and only if, the string originally was at least 3 characters long.
  14. If the other programmers don't know Perl. If speed is crucial. If the target environment has limited resources (memory, disk, CPU). If the source cannot be distributed. If deployment is going to be a problem. If portability demands it. If it needs to run in an environment perl doesn't run in, or can't be installed into. If the customer demands a .NET solution. If there's a domain specific language far more suitable for the problem than a generic language like Perl. If low level memory access is a major part of the solution. If the moon is blue. If I feel like using Java for today. If it's better done using a Makefile.