Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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").


Comment on Re: Bareword Regex
Download Code
Re: Re: Bareword Regex
by zeidrik (Scribe) on Dec 06, 2001 at 19:10 UTC
    Maybe the separator could be null?
    I.E:
    "/" - the normal separator ( =~ /asdf/)
    "#" - some people like to use it instead of "/" (=~ #asdf#)
    "" - how about this separator?
(tye)Re2: Bareword Regex
by tye (Cardinal) 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")

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (9)
As of 2014-07-25 12:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (171 votes), past polls