Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Essentially regexen are two argument (or three argument or hypothetically four) operators which as far as operators go is pretty weird (note the only common operator like this is the ? : ternary operator. Since the nature of the operator itself has room for, 1, (or two or three depending on how you look at it) additional arguments there needs to be a way to invole the fourth.

Sorry. to convert all that gobbleygook, look at this:

$foo =~ s/bar /baz /x EXPR(1) =~ s/REGEX(2)/STRING_OR_EXPR(3)/MODIFIERS(4)

had the regex operators been expressed as function calls this might have worked as an option set, but notice that in some cases various arguments can be omitted. So if EXPR(1) is omitted $_ is used, in an s/// if REGEX(2) is omitted it uses the last m// pattern on the subject (EXPR(1)), and the modifiers can be omitted. So if this had been positional arguments it would have had a pretty strange argument signature. Try to come up with a reasonable way to pass the arguments into a function based s/// implementation with same behaviour of default operation on $_, and etc. Its not going to be nice, with many common calls using undef in their parameter list. Or alternatively hopelessly verbose like the dotNet regex implementation.

So in short regex like operators need the binding part because its an optional part (at the front no less) of what is essentially a quaternary operator.

Also as a last thought....

my $count=(my $copy=$original)=~s/-(Foo|Bar)-/$1/g;

:-)


---
demerphq

    First they ignore you, then they laugh at you, then they fight you, then you win.
    -- Gandhi



In reply to Re: Re: Why do we say the =~ operator "binds"? by demerphq
in thread Why do we say the =~ operator "binds"? by Cody Pendant

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-04-23 13:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found