in reply to The Behavior of 'do'

do is a keyword (like package or use), not a function.

In your case, print is treated as a bareword . Surely this would not be surprising if you typed

use print;

instead :-)

I presume that Perl behaves in this way because it's more useful for the programmer, being more concise.

Also rememeber that if it looks like a function call, it is a function call.

-- TMTOWTDI

Replies are listed 'Best First'.
Re: Re: The Behavior of 'do'
by tomazos (Deacon) on Jul 27, 2001 at 01:05 UTC
    do print;

    will evaluate print as the bareword name of a FILE and execute it.

    do (print);

    will evaluate print as a LIST and evaluate it as an EXPR, executing the print and then returning the result to do as a EXPR of 1.

    do print();

    will evaluate print as a SUBROUTINE and execute it.

    The first two cases are the file-style do, the last is the old subroutine-style do, and the block-style do has not been shown.