Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Perl6 regex substitutions

by raiph (Friar)
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.


Comment on Re: Perl6 regex substitutions
Download Code

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 chilling in the Monastery: (11)
As of 2014-08-01 16:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (28 votes), past polls