Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Perl Substr

by BillKSmith (Deacon)
on Jun 17, 2013 at 11:13 UTC ( #1039338=note: print w/ replies, xml ) Need Help??


in reply to Perl Substr

Why do you exclude a simple regexp? Marte' example becomes:

use strict; use warnings; my $string1 = "ABCDEFderp12345"; my $string2 = "derp"; if ($string1 =~ m/$string2(.*)$/ ){ print $1, "\n"; }else{ print "$string2 does not occur within $string1"; }
Bill


Comment on Re: Perl Substr
Download Code
Replies are listed 'Best First'.
Re^2: Perl Substr
by AnomalousMonk (Abbot) on Jun 17, 2013 at 12:56 UTC

    Better to meta-quote  $s2 to avoid strange effects from regex metacharacters in it ( //p regex modifier available with 5.10+):

    >perl -wMstrict -le "my $s1 = 'foo not *UN*known but bar is'; my $s2 = '*UN*known'; ;; die qq{'$s2' not in '$s1'} unless $s1 =~ m{ \Q$s2\E }xmsp; print qq{all after: '${^POSTMATCH}'}; " all after: ' but bar is'

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1039338]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (10)
As of 2015-07-30 21:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (273 votes), past polls