Perl Programming Question:
Download Questions PDF

What does $result = f() .. g() really return?

Perl Programming Interview Question
Perl Programming Interview Question

Answer:

False so long as f() returns false, after which it returns true until g() returns true, and then starts the cycle again.
This is scalar not list context, so we have the bistable flip-flop range operator famous in parsing of mail messages, as in `$in_body = /^$/ .. eof()'. Except for the first time f() returns true, g() is entirely ignored, and f() will be ignored while g() later when g() is evaluated. Double dot is the inclusive range operator, f() and g() will both be evaluated on the same record. If you don't want that to happen, the exclusive range operator, triple dots, can be used instead. For extra credit, describe this:
$bingo = ( a() .. b() ) ... ( c() .. d() );

Download Perl Programming Interview Questions And Answers PDF

Previous QuestionNext Question
Why is it hard to call this function: sub y { "because" }Why does Perl not have overloaded functions?