[za-pm] Introducing Darryl Trimming ... with a regex /x modifier problem

Anne Wainwright anotheranne at fables.co.za
Mon May 2 04:47:12 PDT 2011


... and who has just stumped me short of rereading my Friedl.

I have subscribed him to the list just now so he will benefit from your
list posts.

Darryl, are you using regex-coach (a windows thing) which I have always
found the best playground for sorting out regular expressions that
don't do what you tell them?

bestest 
anne

Begin forwarded message:

Date: Mon, 2 May 2011 13:15:54 +0200
From: "Darryl Trimming" <trids at mweb.co.za>
To: <anotheranne at fables.co.za>
Subject: perl help?


Hi Anne

 

I've just started learning perl, and found your contact details here
(http://www.pm.org/groups/522.html) while looking for community help. It
seems a bit out of date, so please forgive me if I'm knocking on the
wrong door.

 

I was exploring the "/x" regexp modifier, and came upon some unexpected
results. Upon closer inspection, my problem lies with the ternary
operator. I can't see why the following results are inconsistent ..

 

          say '1:'.( 'hello' =~ /h e l l o/ )?'true':'false';        #
          no '/x', no match

          say '2:'.( 'hello' =~ /h e l l o/x )?'true':'false';       #
          '/x' ignores spaces, produces '1'

          say '3:'.( 'h e l l o' =~ /h e l l o/x )?'true':'false';   #
          '/x' ignores spaces, no match

 

          say '1:'.( 'hello' =~ /h e l l o/ ).'.';        # no '/x', no
match

          say '2:'.( 'hello' =~ /h e l l o/x ).'.';       # '/x' ignores
spaces, produces '1'

          say '3:'.( 'h e l l o' =~ /h e l l o/x ).'.';   # '/x' ignores
spaces, no match

 

          say '1:'.( 'hello' =~ /h e l l o/ ) && 'true.';        # no
          '/x', no match

          say '2:'.( 'hello' =~ /h e l l o/x ) && 'true.';       # '/x'
ignores spaces, produces '1'

          say '3:'.( 'h e l l o' =~ /h e l l o/x ) && 'true.';   # '/x'
ignores spaces, no match

 

          say '1:'.(( 'hello' =~ /h e l l o/ ) + 0) .'.';        # no
          '/x', no match

          say '2:'.(( 'hello' =~ /h e l l o/x ) + 0) .'.';       # '/x'
ignores spaces, produces '1'

          say '3:'.(( 'h e l l o' =~ /h e l l o/x ) + 0) .'.';   # '/x'
ignores spaces, no match

 

          say '1:'.(( 'hello' =~ /h e l l o/ ) +
          0)?'true':'false';        # no '/x', no match

          say '2:'.(( 'hello' =~ /h e l l o/x ) +
          0)?'true':'false';       # '/x' ignores spaces, produces '1'

          say '3:'.(( 'h e l l o' =~ /h e l l o/x ) +
          0)?'true':'false';   # '/x' ignores spaces, no match

 

.. where only the highlighted sections above yield the expected
results. All the others always return 'true'.

 

If you can't help, then please point me in the right direction for
community support.

 

Many thanks and kind regards

DT

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/za-pm/attachments/20110502/3b36f78d/attachment.html>


More information about the Za-pm mailing list