Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Naked quotes work like m//?

by tachyon (Chancellor)
on Dec 03, 2004 at 23:25 UTC ( #412310=note: print w/ replies, xml ) Need Help??


in reply to Naked quotes work like m//?

I too have noted that 'bug' as well which as you note turns out not to be one. It is possibly a documentation bug. Probably like me you remembered reading If ``/'' is the delimiter then the initial m is optional in perlre and then made the assumption (IMHO justified) that this implicitly indicates that:

If ``/'' is NOT the delimiter then the initial m is NOT optional.

This of course is an implicit assumption. perlre does not define the behaviour when the delimiter is not a / and the m is missing. As you note the m is optional with a (small) range of other delimiters. This dates back to Perl 5.6.0 and perhaps earlier.

There are actually only a limited number of delimiters that will work in this /* m free, non /* context. Essentially any perl expression that will evaluate as a stringy thing and is a valid RVALUE can be used:

$a = "2foobar\n"; print $a if $a =~ m"foo"; print $a if $a =~ eval{"bar"}; print $a if $a =~ q!foo!; print $a if $a =~ (6*7-40); # yes this evaluates to 2, gets stringif +ied and matches

Practically speaking that means " and ' with most of the other commonly used non / regex delims like ! , | {} all creating syntax errors or not matching.

cheers

tachyon


Comment on Re: Naked quotes work like m//?
Download Code
Re^2: Naked quotes work like m//?
by BUU (Prior) on Dec 04, 2004 at 05:09 UTC
    I'm so confused as to what you're going on about here. The code cited in the original post has absolutely nothing to do with "alternate delimiters for m//" and the various other things you're going on about.

    All that is happening is that =~ will use ANY SCALAR on the right hand side as a regex. It stringifies it and treats that value as a regex, then applies it to the left hand as normal.

    So in short, anything that produces a scalar can be used on the right hand side of the =~ operator, including, for example:
    $a =~ { foo }; $b =~ [ "bar" ];
    And so forth. The "m" isn't optional for these because they aren't regexes! They're simply scalar producers.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (12)
As of 2014-09-16 14:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (31 votes), past polls