develooper Front page | perl.perl5.porters | Postings from April 2010

RFC: Perl manual pages -- Style issue: compounds and spacing in conditionals

Thread Next
From:
Jari Aalto
Date:
April 10, 2010 03:14
Subject:
RFC: Perl manual pages -- Style issue: compounds and spacing in conditionals
Message ID:
877hofzkap.fsf@jondo.cante.net

Examples from POD

    while (<>)
    while ( <> )

    while (/(\w+)\s+fish\b/gi) {
        ...
    }

    if (/=item (\S+)/ and $level == 1) {
        ...
    }

    if ($person->{role} =~ /kid|son|daughter/) {
        ...
    }

    if ($email =~ /([^@]+)@(.+)/) {
        ...
    }

    while (my($key,$val) = each %HIST) {
        ...
    }

What do you think about making a little more room inside parens:

    while ( <> )

    while ( /(\w+)\s+fish\b/gi ) {
        ...
    }

    if ( /=item (\S+)/  and  $level == 1 ) {
        ...
    }

    if ( $person->{role} =~ /kid|son|daughter/ ) {
        ...
    }

    if ( $email =~ /([^@]+)@(.+)/ ) {
        ...
    }

    while ( my($key,$val) = each %HIST ) {
        ...
    }


REFERENCES

Perlintro.pod suggests:

=item if

    if ( condition ) {
        ...
    } elsif ( other condition ) {
        ...
    } else {
        ...
    }

There's also a negated version of it:

    unless ( condition ) {
        ...
    }

=item while

    while ( condition ) {
        ...
    }

There's also a negated version, for the same reason we have C<unless>:

    until ( condition ) {
        ...
    }


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About