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

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

Thread Previous | Thread Next
From:
Tom Christiansen
Date:
April 10, 2010 05:32
Subject:
Re: RFC: Perl manual pages -- Style issue: compounds and spacing in conditionals
Message ID:
15492.1270902736@chthon
> 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 ) {
>        ...
>    }

What you've misunderstood is that the surrounding space in those is
there solely because standard POD as no mechanism for specifying what
would be an oblique courier font in an indented paragraph.  In dialects
that understand R<> in literal podagraphs standing for "replacement"
text, those would be written:

     if (R<CONDITION>) {
         ...
     } elsif (R<OTHER CONDITION>) {
         ...
     } else {
         ...
     }

     unless (R<CONDITION>) {
         ...
     }

etc.  If it were troff, it would likely be something as elaborate as:

    if (\|\s-1\f(CWCONDITION\fP\s0\|) {

where the sixth-of-an-em space denoted by \| would be used only if the
kerning looked wrong by clobbering the parens in the font transition
between Courier and Oblique Courier, as sometimes occurs.  

The space in the simpler pod is only there to make the meta-ness of
the condition stand out.  It wouldn't be used in actual code, and in
fact, is not:

    % man perlintro | tcgrep '^\s+(if|while|unless|until)\s*\('
               if (@animals < 5) { ... }
           if ($some_condition) {
               if ( condition ) {
               unless ( condition ) {
               if ($zippy) {
               while ( condition ) {
               until ( condition ) {
           while (<$in>) {     # assigns each line in turn to $_
               if (/foo/)       { ... }  # true if $_ contains "foo"
               if ($a =~ /foo/) { ... }  # true if $a contains "foo"
               while (<>) {
               if ($email =~ /([^@]+)@(.+)/) {

See the difference?

--tom

Thread Previous | 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