what the mx mean in case

33 views
Skip to first unread message

Teoh khah swee

unread,
Mar 9, 2014, 6:58:00 PM3/9/14
to puppet...@googlegroups.com
HI all, 

I just come across an case statement for puppet. I would like to know what the means of the mx for below sample code?

case $::operatingsystem {
   /(?-mx:AIX)/ :{

Matt Zagrabelny

unread,
Mar 10, 2014, 10:37:21 AM3/10/14
to puppet...@googlegroups.com
From:

http://perldoc.perl.org/perlre.html

(?adlupimsx-imsx)
(?^alupimsx)
One or more embedded pattern-match modifiers, to be turned on (or
turned off, if preceded by - ) for the remainder of the pattern or the
remainder of the enclosing pattern group (if any).

(?adluimsx-imsx:pattern)

m:
Treat string as multiple lines. That is, change "^" and "$" from
matching the start or end of line only at the left and right ends of
the string to matching them anywhere within the string.

x:
Extend your pattern's legibility by permitting whitespace and comments.

I would then say that puppet is looking for AIX without capturing it
and has turned off the m and x options for this pattern match.

-mz

Joachim Schrod

unread,
Mar 10, 2014, 1:09:22 PM3/10/14
to puppet...@googlegroups.com
I don't know if Ruby regexps are really exactly the same as Perl
regexps, but, to me as a Perl programmer, this regexp looks
semantically identical to /AIX/, just with some added garbage to
irritate people who don't know enough about regexps... ;-)

No alternative or other grouping construct is used, thus the
capture vs. collection functionality is irrelevant. The m flag
modifier is turned off by default, no need to turn it off manually.
The regexp has neither whitespace nor comments, thus the state of
the x flag modifier is irrelevant either.

But then, that's just from the viewpoint of an experienced Perl
programmer; maybe Ruby is different here.

Joachim

--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Joachim Schrod, Roedermark, Germany
Email: jsc...@acm.org

jcbollinger

unread,
Mar 11, 2014, 9:32:39 AM3/11/14
to puppet...@googlegroups.com


There's no need to speculate about Perl vs. Ruby (vs. Puppet) regexes, when instead we can go straight to the docs: http://docs.puppetlabs.com/puppet/3/reference/lang_datatypes.html#regular-expressions.  We see there that Puppet accepts options m, x, and i, which have the same meaning to Puppet as to Ruby and Perl (multiline mode, (in)significant whitespace/comment mode, and case-insensitive mode, respectively).

Since all these options are off by default, Joachim is right: the regex presented means exactly the same thing as /AIX/, and explicitly declaring the options off does nothing but obfuscate.


John

Reply all
Reply to author
Forward
0 new messages