Quaintness involving the /x modifier, a comment and slash... 
Author Message
 Quaintness involving the /x modifier, a comment and slash...

  (Or was that a backslash; I never could tell... )

  Before I go ahead and make a fool of myself on p5p, I thought I'd do
  so here - with the hope of being told that I am wrong. Quaint notion...

  Anyway. When I write (for me) complex regexp's, I tend to use the /x
  modifier, in order to be able to get some comments in there.

  Consider, then, the following (numbered) example:

01   $Text =~ s/
02              <                           # One '<'
03              xref                        # The word 'xref'
04              >                           # One '>'
05              .+?                         # One, or more, of anything
06              <                           # One '<'
07              \/                          # One '/'
08              xref                        # The word 'xref'
09              >                           # One '>'
10             //igx ;

  What this does is, in the context of this letter, not interesting at
  all. Do look closely at line 07. Inside the comment is a slash - '/'

  Sending this through Perl 5.003 or 5.004 produces the rather surprising
  message:

   'Illegal division by zero at convert_sql.pl5 line 121.'

  This interested me. I'll try to escape the '/':

01   $Text =~ s/
02              <                           # One '<'
03              xref                        # The word 'xref'
04              >                           # One '>'
05              .+?                         # One, or more, of anything
06              <                           # One '<'
07              \/                          # One '\/'
08              xref                        # The word 'xref'
09              >                           # One '>'
10             //igx ;

  This worked. Being the curious sort, I tried to write a '/' inside a
  regular comment. That gave no errors. Refering back to the perlre
  manpage enlightened me not the least. Refering (forward >:) to the
  FAQ gave me:

    "The /x modifier causes whitespace to be ignored in a regexp pattern
     (except in a character class), and also allows you to use normal
     comments there, too. As you can imagine, whitespace and comments
     help a lot"

  That says *normal* comments - can someone tell me how much egg I have
  on my face, and why ?? It *does* seem that a / can be *un* escaped in
  regular comments, but *not* in /x-comments - yet the FAQ clearly states
  that 'normal' comments can be used.

  So, is the bug in Tina or in Perl ?

  (Ohyes, and if its in Tina, I think I'll reconsider going to PerlC 2.0 >:)

--

                                                                    - TiM



Fri, 22 Dec 2000 03:00:00 GMT  
 Quaintness involving the /x modifier, a comment and slash...

[posted and cc'd]

Tina> What this does is, in the context of this letter, not
Tina> interesting at all. Do look closely at line 07. Inside the
Tina> comment is a slash - '/'

Abigail already ran across this one, and reported it about a month
ago:

   http://www.rosat.mpe-garching.mpg.de/mailing-lists/perl-porters/1998-...

the final outcome was basically a doc patch:

   http://www.rosat.mpe-garching.mpg.de/mailing-lists/perl-porters/1998-...

which can be distilled to: "be careful about putting pattern
delimiters into comments when you do /x-style regexps."

for your current situation, try using matched delimiters, or some
other symbol (like maybe a colon or an exclamation mark.)

t.
--
Tkil * <URL: http://www.scrye.com/~tkil> * hopelessly hopeless romantic.
  "So amplify this little one      |   She hears as much as she can see
   She's a volume freak         |   And what she sees, she can't believe."
        -- Catherine Wheel, _Happy Days_, "Judy Staring At The Sun"



Fri, 22 Dec 2000 03:00:00 GMT  
 Quaintness involving the /x modifier, a comment and slash...


Quote:
> Tina> What this does is, in the context of this letter, not
> Tina> interesting at all. Do look closely at line 07. Inside the
> Tina> comment is a slash - '/'

> Abigail already ran across this one, and reported it about a month
> ago:

  Ah; it just goes to show - I really should keep up with the p5p list.
  Digging into my 5k+ unread p5p mail I found it; thankyou.

  Atleast it *could* be seen as a bug, and subsequently I'll see ya'all
  at the conference. I'm the short girl with a face full of egg >:)

--
  Tina Marie Holmboe                


  Scandinavia Online AB Development Dept.    (+46) 08 587 81000 (switchboard)
                                             (+46) 08 587 81189 (direct)



Sat, 23 Dec 2000 03:00:00 GMT  
 Quaintness involving the /x modifier, a comment and slash...

Quote:
>Abigail already ran across this one, and reported it about a month
>ago:

>   http://www.rosat.mpe-garching.mpg.de/mailing-lists/perl-porters/1998-...

>the final outcome was basically a doc patch:

>   http://www.rosat.mpe-garching.mpg.de/mailing-lists/perl-porters/1998-...

>which can be distilled to: "be careful about putting pattern
>delimiters into comments when you do /x-style regexps."

I had the opposite problem a while ago.  I was using extended
regexes and needed a "#" as part of the pattern itself.  Where
normally that wouldn't need to be escaped (if not using /x), I had
to use "\#" instead.

Perhaps that should go into the docs as well...?  I don't know -
to me it seems obvious that you'd need to backwhack the pound, but
then I think, perhaps that's the clarity of hindsight!



Sun, 24 Dec 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. simple regex question involving o modifier

2. Comment modifier un fichier dans un répertoire

3. Changing back slashes to forward slashes

4. Are # comments really comments?

5. How to comment a space in reg exp when using /x modifier?

6. using precompiled regexes with the //s modifier

7. Why only a single statement modifier?

8. /o modifier in regex

9. Newbie question regarding local modifier

10. Regex Variable String ends in slash

11. variable modifiers

12. Statement modifiers

 

 
Powered by phpBB® Forum Software