develooper Front page | perl.perl6.compiler | Postings from March 2005

Questions regarding s/// and subst?

Thread Next
Stevan Little
March 23, 2005 08:15
Questions regarding s/// and subst?
Message ID:
Hello All,

I have been asking Autrijus about getting the substitution regexp 
working in Pugs, and a few issues have come up which need some 

In the Smart Matching table in Synopsis 04, there is a mention of 
'subst' (here is that snippet so you don't have to go digging):

     $_      $x        Type of Match Implied    Matching Code
     ======  =====     =====================    =============
     Any     subst     substitution match*      match if $_ ~~ subst

This seems to be the first mention of 'subst', and no real 
clarification followed after. I search the other Synopsis and found it 
again, all the way a the very very very bottom of Synopsis 05, where it 
is mentioned as a method form of s/// (again here is the snippet):

	There are also method forms of C<m//> and C<s//>:

     	$str.subst(//, "replacement")
     	$str.subst(//, {"replacement"})
     	$str.=subst(//, "replacement")
     	$str.=subst(//, {"replacement"})

This though, only seemed to muddy the waters more.

Further discussion on #perl6 lead to more questions regarding subst and 
s///. What follows is the list of questions raised by this 

Is subst an object/type?
Or is it a method of the Str object?

If it is an object ...
	Does s/// produce a subst object?
	Does a subst object .hasa rule object(s)?
		If so can we extract those rule object(s) from it?
	What exactly does a subst object do?
	How does a subst object stringify?
	Etc. etc. etc.

If it is a method ...
	How would a method on the right hand side of ~~ work exactly?
		~~ s:perl5:g/a/b/
	the same as
		~~ .subst(rx:perl5/a/, "b")
		~~ .subst(rx:perl5/a/, {"b"})



Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About