lamp has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's minimum standard of quality and will not be displayed.
  • Comment on Difference between 'print while' and 'while print'

Replies are listed 'Best First'.
Re: Difference between 'print while' and 'while print'
by edan (Curate) on Feb 02, 2005 at 10:17 UTC

    You should probably read perldoc perlsyn, looking at the sections entitled "Simple Statements" and "Compound Statements". This will explain the difference in syntax. The short of it is that "print while (CONDITION);" is a simple statement (print) with a "modifier" (while), whereas "while(CONDITION){print}" is a compound statement, consisting of the while (and its associated CONDITION) followed by the BLOCK of code to be executed. It's a purely syntactic difference.

    --
    edan

Re: Difference between 'print while' and 'while print'
by Corion (Patriarch) on Feb 02, 2005 at 10:06 UTC

    The first one starts with the letter "p". The second one starts with the letter "w".

    Maybe you want to be more explicit in what you ask. You might want to read How (Not) To Ask A Question by jeffa, and you might also want to read the Perl documentation for while and print, as found via the commands perldoc -f while and perldoc -f print.

    Perl evaluates most of its statements in a left-to-right fashion, which implies that the order in which things appear is relevant.

Re: Difference between 'print while' and 'while print'
by demerphq (Chancellor) on Feb 02, 2005 at 12:22 UTC
    1 while print $fh "foo";

    is different from

    print $fh "foo" while 1;

    The first one will stop when the print eventually fills up the device that its writing to, the second one wont.

    ---
    demerphq

Re: Difference between 'print while' and 'while print'
by prasadbabu (Prior) on Feb 02, 2005 at 10:08 UTC
    print "hi" while (1); while (1){print "yes";}

    see is there any difference?

    Prasad