Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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?
[james28909]: foreach server this bot is on, the gateway sends me a json response, which i parse out all the info with JSON, and this response has user information, i need to be able to add a user, and then update the user info when they join/leave rooms ect
[james28909]: i think im good
[james28909]: i just watched a youtube video
[karlgoethebier]: james28909: Did you look on CPAN?
[james28909]: lol
[karlgoethebier]: james28909: Super Search here ?
[karlgoethebier]: james28909: No kidding

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (11)
As of 2017-05-25 16:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?