[Purdue-pm] Why does this work?

Mark Senn mark at ecn.purdue.edu
Wed Apr 4 13:32:51 PDT 2012


    Bradley Andersen wrote:
    > #!/usr/bin/env perl
    > 
    > use strict;
    > use warnings;
    > 
    > use feature 'say';
    > 
    > for my $i(1 .. 10) {;
    >     say $i;
    > }
    > 
    > ?? Why does that work?

>From "http://perldoc.perl.org/perlsyn.html":
    The foreach keyword is actually a synonym for the for keyword,
    so you can use foreach for readability or for for brevity.

The "{;" doesn't cause problems because the statement between
"{" and ";" is zero length and zero length statements are allowed.
This code works fine
    ;;;;;
    say 'hello'
    ;;;;;

-mark


More information about the Purdue-pm mailing list