Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Best practice or cargo cult?

by davorg (Chancellor)
on Jun 20, 2006 at 14:47 UTC ( #556410=note: print w/ replies, xml ) Need Help??


in reply to Best practice or cargo cult?

As I understand it, these options will all effectively be turned on by default in the Perl 6 regex engine. So either Larry has decided that they are, in fact, best practice or Damian has sneaked them into the specs whilst Larry wasn't watching.

--
<http://dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg


Comment on Re: Best practice or cargo cult?
Re^2: Best practice or cargo cult?
by Juerd (Abbot) on Jun 20, 2006 at 15:00 UTC

    As I understand it, these options will all effectively be turned on by default in the Perl 6 regex engine. So either Larry has decided that they are, in fact, best practice or Damian has sneaked them into the specs whilst Larry wasn't watching.

    Firstly, Perl 6 is not Perl 5.

    Secondly, Perl 6 gives you \N, a convenient way to write <-[\n]> (that's [^\n]). It's worse than ., but acceptable. Writing [^\n] all the time is a hard exercise for one's fingers, and makes for messy code. That's why I strongly believe you should only use /s when you really want . to include the newline character.

    /m won't be turned on by default in Perl 6. Instead, we get different metacharacters for begin/end of line versus string. So again it gives best of BOTH worlds.

    As for /x... I have no strong opinion about that. I don't think /\A\d+\z/ is unreadable, but I don't mind /\A \d+ \z/x at all.

    Juerd # { site => 'juerd.nl', do_not_use => 'spamtrap', perl6_server => 'feather' }

      \N could easily be added to blead. Ill check into it.

      ---
      $world=~s/war/peace/g

        \N{...} is already a recognized pattern in perl5 regexp language. Pick something else and add it to your current perl using the instructions at Extending Regular Expression Syntax. It's a presentation I gave to Minneapolis.pm last year. Or... co-opt \N for your own use. It isn't as if \N is so common that you'd miss it if you stole it away from perl. In my demo I redefined \w and \b to something more appropriate for my own set of common tasks.

        ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

        In fact, here's the implementation. This works in perl5 going back to uh... early? Have your cake today. Not that I tested it. It's simple enough I just penned this and didn't bother running it.

        use Regexp::SlashN; "A B C" =~ /(\N+)/; $1 eq "A B C" or die;

        Regexp/SlashN.pm

        package Regexp::SlashN; use overload; sub import { overload::constant qr => \ &convert } # A simple table of definitions my %syntax = ( '\\' => '\\', N => '[^\n]', ); sub convert { my ( $re ) = @_; $re =~ s/\\([\\N])/$syntax{$1}/g; return $re; }

        ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (16)
As of 2014-08-29 12:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (280 votes), past polls