Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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/-/;


  • 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.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1077290]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2018-01-17 21:27 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (206 votes). Check out past polls.