Berkeley CSUA MOTD:2011:January:19 Wednesday
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2011/1/19-2/19 [Computer/SW/Languages/Perl] UID:54012 Activity:nil
1/19    Perl god, please go to http://perldoc.perl.org/perlre.html
        Go to "Quantifiers" and the greedy operator, such as
        +?, *?, ??, {n,}?, {n,m}?
        So I understand the greedy operator that does matching
        based on having different choices (instead of the default
        maximal munch). What about "{n}?" ?  What are some
        examples of using "{n}?" ?
        \_ s{2,} will match "ssss" once.  s{2,}? will match it twice.
           \_ that is clear. s{n,} and s{n,m} will match between n to
              m number of s. Traditionally regex is maximal munch.
              However the "?" minimal munch operator such as s{n,m}?
              will perform minimal munch.
                My question is, if you have just s{n} and you match
              exactly n number of s, then what is the point of the
              minimal match, given that there is no choice?
              \_ It's just for consistency.  s{n} and s{n}? are identical.
                 \_ ^consistency^redundancy
                    ^consistency^stupidity
                    Perl programmers are like Republicans-- righteous,
                    unapologetic, and incapable of seeing the point
                    of view from other languages.
                    \_ How would you design it?  If s{2,3}? is legal but
                       s{2,2}? is an error, then s{$min,$max}? will fail
                       if $min and $max happen to be equal.  That seems
                       suboptimal.
        \_ "$_Wha???" lol
Berkeley CSUA MOTD:2011:January:19 Wednesday