in reply to Re: RegEx for OpenOffice::OODoc as in $doc->selectElementsByContent()
in thread RegEx for OpenOffice::OODoc as in $doc->selectElementsByContent()

Thanks for the tip! I like using qr//i better because it is easier to understand. With that construct, months from now, I'll look at the code and understand how it works (or how to modify it for another different task).

As usual, it's not evident to me why the need for null concatenation, but it's not too important since it works.

Thanks,
  EigenFunctions
  OpSys: Win7 Professional/Home Premium x64 Service Pack 1

  • Comment on Re^2: RegEx for OpenOffice::OODoc as in $doc->selectElementsByContent()
  • Download Code

Replies are listed 'Best First'.
Re^3: RegEx for OpenOffice::OODoc as in $doc->selectElementsByContent()
by AnomalousMonk (Archbishop) on Jun 04, 2016 at 22:09 UTC
    ... it's not evident to me why the need for null concatenation ...

    I haven't looked at the docs or source at all, but apparently the  selectElementsByContent() method does not like to be passed a reference. The  qr// operator returns a  Regexp reference. In essence, the  "". qr/faith/i expression replicates the approach of choroba above by stringizing this reference before passing it as an argument, but still allowing all the facility of the  qr// operator to form the pattern object in the first place: all the i-s and t-s get properly dotted and crossed, respectively. (You crotted an i in the solution you attempted here.) I feel it's almost always better to use  qr// to build patterns than than to try to express the patterns as strings using string operators that are almost, but not quite, the same.

    Here's an example of conversion of a  Regexp object to a string and its subsequent use as a string in a match.

    c:\@Work\Perl\monks>perl -wMstrict -le "my $rx = qr{ (?i) f a i t h }xms; print 'qr// object: ', ref_or_not($rx); print $rx; ;; my $rx_stringized = '' . $rx; print 'stringization: ', ref_or_not($rx_stringized); print qq{'$rx_stringized'}; ;; my $s = 'UnFaItHfUl'; $s =~ $rx_stringized; print qq{'$&'}; ;; sub ref_or_not { my $scalar = shift; return ref $scalar ? ref $scalar : 'not a ref'; } " qr// object: Regexp (?^msx: (?i) f a i t h ) stringization: not a ref '(?^msx: (?i) f a i t h )' 'FaItH'
    Note that the  =~ operator is quite happy to use a pure string as a match pattern.


    Give a man a fish:  <%-{-{-{-<

      Thank-you for the explanation, I now understand. I appreciate the effort very much.

      Thanks,
        EigenFunctions
        OpSys: Win7 Professional/Home Premium x64 Service Pack 1