.. & ...

kappa on 2010-01-21T14:15:31

I'm publishing one of the tricky questions I ask when I interview people for Perl developer positions.

"Tell me about .. and ... operators? How are they different? How do they work in different contexts?" © skv++

Why it is a bad question: nobody (and I mean, really, nobody) ever uses these operators in scalar context. The only way to really know them is to have literally learnt all the perlop by heart. I once did it because I studied Perl offline and the information to feed upon was very scarce.

Why it is a good question: it allows me to know whether the man understands Perl contexts in 30 seconds.

IMHO, this question brings more grief than benefit so I hereby decide to ditch it. Hooray!


Scalar Context

davorg on 2010-01-21T15:49:36

nobody (and I mean, really, nobody) ever uses these operators in scalar context

I'm not saying it's common, but I've certainly used those operators in scalar context.

while (<SOMEFILE>) {
  print if 10 .. 20;
}

Or perhaps:

while (<SOMEFILE>) {
  print if /START/ ... /END/;
}