On 15-Dec-01, Joel Neely wrote:

>> Perhaps Joel would now like to write a version in Perl that's
>> designed to be as clear as possible as apposed to as short as
>> possible?
>> 

> To the everyday Perl hacker, what I published actually is both!
> No, really!  ;-)  The only things I could do to obviousify the
> script would be to write an explicit read/print loop (that's
> what the -p switch does) and embed comments in the RE that
> is the match pattern for the substitution.  That would give us
> something like the following:

> 8<----------
> #!/usr/bin/perl -w

> while (<>) {      # loop over all input (all file arguments)
>    s/            # substitute in current line for this pattern...
>        \b        # boundary (e.g. whitespace or beginning of line)
>        (         #    begin subpattern
>            \d{3} #        exactly three digits
>            -     #        followed by a hyphen
>        )?        #    end subpattern and make it optional
>        \d{3}     # exactly three digits
>        -         # followed by a hyphen,
>        \d{4}     # exactly four more digits, and
>        \b        # a boundary (whitespace or end of line)
>    /####/gx;     # ... four octothorps wherever possible
>    print;        # print current line after substitution(s)
> }
> 8<----------

> but the addition of all the comments is hardly an improvement to
> a Perl programmer.  That would be like showing someone who knows
> elementary algebra a paragraph of text that describes the quadratic
> formula, instead of simply writing (pardon the ASCII art...)

>           ____________
>       +  /  2
>    -b - /  b  -  4 a c
>        V
>    -------------------
>            2 a

> The notation really is intended to be minimalist; the price of
> using it is taking a little time to learn something new, as is
> the case with all programming languages.  I suspect the person
> that has never seen REBOL before would find the comparable
> PARSE rule less than obvious as well.

Fair enough, though there is a "read", a "parse" and a "change" in my
REBOL example which does give some indication of what's being done
with the file-name, while the file-name is the only thing any
outsider would recognise in your Perl example.

> Of course, I could define variables to hold the parts of the RE
> and give them mnemonic names ...

> 8<----------
> #!/usr/bin/perl -w

> my $areacode = '(\d{3}-)?';  # 3 digits and hyphen, optional
> my $exchange = '\d{3}-';     # 3 digits and hyphen
> my $localine = '\d{4}';      # 4 digits

> my $phonenbr = "$areacode$exchange$localine";

> while (<>) {                  # loop over all input
>    s/\b$phonenbr\b/####/gx;  # hiding phone numbers in each line
>    print;                    # and print the line
> }
> 8<----------

> ... but anyone who knows Perl will see that I had to do something
> subtle to make that work.

> Perhaps that would be more readable to some?  What would one do
> in REBOL to make the PARSE rules more obvious to someone who
> doesn't speak REBOL as a native?

> -jn-

-- 
Carl Read

-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the 
subject, without the quotes.

Reply via email to