Note: Beware! Default reply-to is to the list.

... 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" <tr...@mweb.co.za>
To: <anothera...@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

 

 

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

 

 

_______________________________________________
Za-pm mailing list
Za-pm@pm.org
http://mail.pm.org/mailman/listinfo/za-pm

posts also archived on Mail Archive
http://www.mail-archive.com/za-pm@pm.org/

Reply via email to