>That empty list to force the proper context irks me.  How about a
>modifier to the RE that forces it (this would solve the "counting matches"
>problem too).

>       $string =~ m{
>           (\d\d) - (\d\d) - (\d\d)
>           (?{ push @dates, makedate($1,$2,$3) })
>       }gxl;

>       $count = $string =~ m/foo/gl;           # always list context

The reason why not is because you're adding a special case hack to 
one particular place, rather than promoting a general mechanism
that can be everywhere.  

Tell me: which is better and why.

1) A regex switch to specify scalar context, as in a mythical /r:

    push(@got, /bar/r)

2) A general mechanism, say for example, "scalar":

    push(@got, scalar /bar/)

Obviously the "scalar" is better, because it does not require that
a new switch be learnt, nor is its use restricted to pattern matching.
Furthermore, it's inarguably more mnemonic for the sense of "match this
scalarishly".

Likewise, to force list context (a far less common operation, mind
you), it is a bad idea to have what amounts to a special argument
to just one function to this.  What happens to the next function you
want to do this to?  How about if I want to force getpwnam() into list
context and get back a scalar result?

    $count = getpwnam("tchrist")/l;
    $count = getpwnam("tchrist", LIST);
    $count = getpwnam("tchrist")->as_list;

All of those, frankly, suck.  This is much better:

    $count = () = getpwnam("tchrist");

It's better because 

  * You don't have to invent anything new, whether syntactically
    or mnemonically.  The sucky solution all require modification
    of Perl's very syntax.  With the list assignment, you just need
    to learn how to use what you *already have*.  I could say as
    much for (?{...}).  Think how many of the suggestions on these
    lists can be dealt with simply through using existing features
    that the suggesting party was unaware of.

  * It's a general mechanism that isn't tailored for this particular
    function call.  Special-purpose solutions are often inferior
    to general-purpose ones, because the latter are more likely to 
    be creatively usable in a fashion unforeseen by the author.

  * What could possibly be more intuitive for the action of acting
    as though one were assigning to a list than doing that very
    thing itself?  Since () is the canonical list (it's empty, after
    all), this follows directly and requires on special knowledge
    whatsoever.

--tom

Reply via email to