Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Bareword Regex

by virtualsue (Vicar)
on Dec 06, 2001 at 18:34 UTC ( #129916=note: print w/replies, xml ) Need Help??

in reply to Bareword Regex

If you play with this fragment, it helps to use
print "match, $&\n"
to see the actual match.

While we're on the topic, davorg pointed me to a post by chipmunk which in turn points to a piece of Perl poetry that he wrote using "m mmm" (which as we've now seen, could also have been written as "mmmm").

Replies are listed 'Best First'.
(tye)Re2: Bareword Regex
by tye (Sage) on Dec 06, 2001 at 20:39 UTC

    Just to pick a couple of nits in the interest of increasing understanding...

    In that poem, the "m mmm" could be replaced with any bareword simply because the poem "won't run" and without strict, throwing around barewords is unlikely to cause compilation errors.

    However, if "m mmm" was used in code to actually match something (being a silly way of writing "m//m"), then you could never replace it with "mmmm".

    First, m//m is pretty silly code itself. The empty pattern means "reuse the most recent successful regex", and testing (since I so doubt it is documented that I didn't even look for it) shows that when using the empty regex this way, any options are ignored (including /g!); note that this might be considered a bug and get fixed some day, so don't rely on that behavior. So it boils down to being the same as m//, m//mg, m//g, or any other similar code.

    But if we wanted to the code to compile to the same optree, then we could replace "=~ m mmm" with "=~ mmm" (note only 3 "m"s, not 4) provided we either didn't use strict or used a version of Perl that doesn't give an error in this case. However, in the absence of "=~", replacing "m mmm" with "mmm" will change the code from m//m (which matches against $_ since there is no "=~") to 'mmm' (which is simply a string constant) unless something else gets in the way such as strict or the declaration of a subroutine named "mmm".

            - tye (but my friends call me "Tye")
Re: Re: Bareword Regex
by zeidrik (Scribe) on Dec 06, 2001 at 19:10 UTC
    Maybe the separator could be null?
    "/" - the normal separator ( =~ /asdf/)
    "#" - some people like to use it instead of "/" (=~ #asdf#)
    "" - how about this separator?

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2018-02-25 19:53 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (314 votes). Check out past polls.