Re: RFC 164 (v1) Replace =~, !~, m//, and s/// with match() and subst()

[email protected] (Jonathan Scott Duff)
Newsgroups perl.perl6.language.regex
Message-ID <[email protected]>
On Sun, Aug 27, 2000 at 07:29:33PM -0000, Perl6 RFC Librarian wrote:
> This RFC proposes that C<m//> and C<s///> be dropped from the language
> altogether, and instead be replaced with new C<match> and C<subst>
> builtins, with the following syntaxes:
> 
>    $res = match /pattern/flags, $string
>    $new = subst /pattern/newpattern/flags, $string

I think that C<subst> is too syntactically close yet semantically far
from C<substr> that the evil demons of confusion will rear their ugly
heads.

>    match;                  # all defaults (pattern is /\w+/?)

Er, why?  I usually check for the inverse:

	while (<>) { 			while (<>) {
	    next if /^\s*$/;		    next unless match; 
	}				}

Hmm, now that I write it, it doesn't seem so bad.  *Except* that
"match" isn't a good description of what's going on.

>    subst;                  # like s///, pretty useless :-)

Given the above, why not make a bare C<subst> do something equally
useful?  Here are some ideas:

	subst;		# removes leading whitespace
	subst;		# removes trailing whitespace
	subst;		# removes leading and trailing whitespace
	subst;		# synonym for chomp  (Okay, it's a stretch :-)

>    next if /\s+/ || /\w+/;          next if match /\s+/ or match /\w+/;

Gosh this is annoying.  I *really* don't want to have to type "match"
all the time.  And now I have to use C<or> rather than C<||>, which is
already ingrained in my head  (I rarely use "or" or "and")

> Finally, it requires a little too much typing still for my tastes.

Indeed.

> Perhaps we should make "m" and "s" at least shortcuts to the names,
> possibly allowing users to bind them to the front of the pattern
> (similar to some of RFC 138's suggestions). Maybe these two could be
> equivalent:
> 
>     $new = subst /old/new/i, $old;   ==    $new = s/old/new/i, $old;
> 
> And then it doesn't look that radical anymore. This is similar to RFC
> 138, only C<$old> is not modified.

I wonder what happens when people start typing 

	$new = subst s/old/new/i, $old;

-Scott
-- 
Jonathan Scott Duff
[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.