Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Perl6 regex substitutions

by raiph (Chaplain)
on Mar 06, 2014 at 20:52 UTC ( #1077290=note: print w/replies, xml ) Need Help??


in reply to Perl6 regex substitutions

This post is about the immature Perl 6, not the rock solid Perl 5

Perl 6:

my $x = "this is a test"; $x ~~ s:g/\s/-/;

Notes:

  • P6 uses strict mode by default, so I've added a 'my'.
  • The P6 smartmatch operator (~~) covers many cases including ones covered by =~ in Perl 5.
  • In P6 :g is a regex modifier, in this case making the search/replace global. (In Perl 5 it would have been specified as s///g.)
  • In effect P6 regex all have the equivalent of Perl 5's /x regex modifier set on. You can't switch it off. The \s is one of several whitespace alternatives available.

If you want any further help regarding Perl 6, I strongly recommend a visit to the IRC channel #perl6 on freenode, but I'all also check in here to see if you post a follow up.

Hth.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1077290]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2016-10-01 18:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?






    Results (5 votes). Check out past polls.