Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

compiled regex (?: \/ foo) matches and returns 'undef'

Status
Not open for further replies.

pxs42

Programmer
Nov 12, 2007
1
US
( ?: \/ whatever ) matches and returns undef when compiled. the attached perl code I hope is self documenting. What it doesn't show is the different possible flavors of escaping the \/ - ie [\/], \\ \/ - which also fail in the same way.

Any help would be much appreciated.
 
If you want help, it is easier on those helping you if you just include your code in [ignore]
Code:
your code here
[/ignore] tags instead of using an attachment.

Here is your code so included:

Code:
[url=http://perldoc.perl.org/functions/use.html][black][b]use[/b][/black][/url] [green]strict[/green][red];[/red]

[url=http://perldoc.perl.org/functions/sub.html][black][b]sub[/b][/black][/url] [maroon]testit[/maroon] [red]{[/red]
  [url=http://perldoc.perl.org/functions/print.html][black][b]print[/b][/black][/url] [url=http://perldoc.perl.org/functions/shift.html][black][b]shift[/b][/black][/url],[red]'[/red][purple]: [/purple][red]'[/red],[black][b]shift[/b][/black], [red]"[/red][purple][purple][b]\n[/b][/purple][/purple][red]"[/red][red];[/red]
  [url=http://perldoc.perl.org/functions/map.html][black][b]map[/b][/black][/url] [red]{[/red] [black][b]print[/b][/black] [maroon]STDOUT[/maroon] [red]([/red] [url=http://perldoc.perl.org/functions/defined.html][black][b]defined[/b][/black][/url] [blue]$_[/blue] ? [blue]$_[/blue] : [red]'[/red][purple]undef[/purple][red]'[/red] [red])[/red] . [red]"[/red][purple][purple][b]\n[/b][/purple][/purple][red]"[/red] [red]}[/red]  [blue]@_[/blue][red];[/red]
[red]}[/red]

[url=http://perldoc.perl.org/functions/my.html][black][b]my[/b][/black][/url] [blue]$s[/blue] = [red]'[/red][purple]hello mary [/purple][red]'[/red][red];[/red]

[url=http://perldoc.perl.org/functions/our.html][black][b]our[/b][/black][/url] [red]([/red][blue]$tword[/blue],[blue]$tdashed[/blue],[blue]$tslashed[/blue][red])[/red][red];[/red]

[black][b]print[/b][/black] [red]"[/red][purple]uncompiled .... [purple][b]\n[/b][/purple][purple][b]\n[/b][/purple][/purple][red]"[/red][red];[/red]

[blue]$tword[/blue]    = [red]"[/red][purple] [A-Za-z] + [/purple][red]"[/red] [red];[/red]
[blue]$tdashed[/blue]  = [red]"[/red][purple] [blue]$tword[/blue] ( ?: - [blue]$tword[/blue] ) [purple][b]\*[/b][/purple] [/purple][red]"[/red][red];[/red]
[blue]$tslashed[/blue] = [red]"[/red][purple] [blue]$tword[/blue] ( [blue]$:[/blue] [purple][b]\\[/b][/purple] [purple][b]\/[/b][/purple] [blue]$tword[/blue] ) * [/purple][red]"[/red][red];[/red]

[maroon]testit[/maroon][red]([/red][blue]$tdashed[/blue], [blue]$s[/blue], [blue]$s[/blue] =~ [red]/[/red][purple] [blue]$tdashed[/blue] [/purple][red]/[/red][red]gx[/red][red])[/red][red];[/red]
[maroon]testit[/maroon][red]([/red][blue]$tslashed[/blue], [blue]$s[/blue], [blue]$s[/blue] =~ [red]/[/red][purple] [blue]$tslashed[/blue] [/purple][red]/[/red][red]gx[/red][red])[/red][red];[/red]

[black][b]print[/b][/black] [red]"[/red][purple][purple][b]\n[/b][/purple][purple][b]\n[/b][/purple]compiled .... [purple][b]\n[/b][/purple][purple][b]\n[/b][/purple][/purple][red]"[/red][red];[/red]

[blue]$tword[/blue]    = [red]qr/[/red][purple] [A-Za-z] + [/purple][red]/[/red][red]x[/red][red];[/red]
[blue]$tdashed[/blue]  = [red]qr/[/red][purple] [blue]$tword[/blue] ( ?: - [blue]$tword[/blue] ) * [/purple][red]/[/red][red]x[/red][red];[/red]
[blue]$tslashed[/blue] = [red]qr/[/red][purple] [blue]$tword[/blue] ( [blue]$:[/blue] [purple][b]\\[/b][/purple] [purple][b]\/[/b][/purple] [blue]$tword[/blue] ) * [/purple][red]/[/red][red]x[/red][red];[/red]

[maroon]testit[/maroon][red]([/red][blue]$tdashed[/blue], [blue]$s[/blue], [blue]$s[/blue] =~ [red]/[/red][purple] [blue]$tdashed[/blue] [/purple][red]/[/red][red]gx[/red][red])[/red][red];[/red]
[maroon]testit[/maroon][red]([/red][blue]$tslashed[/blue], [blue]$s[/blue], [blue]$s[/blue] =~ [red]/[/red][purple] [blue]$tslashed[/blue] [/purple][red]/[/red][red]gx[/red][red])[/red][red];[/red]

[black][b]print[/b][/black] [red]"[/red][purple][purple][b]\n[/b][/purple][purple][b]\n[/b][/purple]inline .... [purple][b]\n[/b][/purple][purple][b]\n[/b][/purple][/purple][red]"[/red][red];[/red]

[maroon]testit[/maroon][red]([/red][blue]$tdashed[/blue], [blue]$s[/blue], [blue]$s[/blue] =~ [red]/[/red][purple] [A-Za-z] + ( ?: - [A-Za-z] + ) * [/purple][red]/[/red][red]gx[/red][red])[/red][red];[/red]
[maroon]testit[/maroon][red]([/red][blue]$tslashed[/blue], [blue]$s[/blue], [blue]$s[/blue] =~ [red]/[/red][purple] [A-Za-z] + ( ?: [purple][b]\/[/b][/purple] [A-Za-z] + ) * [/purple][red]/[/red][red]gx[/red][red])[/red][red];[/red]
[tt]------------------------------------------------------------
Pragmas (perl 5.8.8) used :
[ul]
[li]strict - Perl pragma to restrict unsafe constructs[/li]
[/ul]
[/tt]

- Miller
 
add double quotes around your data when you pass it to the sub
i.e.
Code:
testit($tdashed, $s, "$s =~ / [A-Za-z] + ( ?: - [A-Za-z] + ) * /gx");
testit($tslashed, $s, "$s =~ / [A-Za-z] + ( ?: \/ [A-Za-z] + ) * /gx");

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top