Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Perl Substr

by BillKSmith (Priest)
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"; }

Replies are listed 'Best First'.
Re^2: Perl Substr
by AnomalousMonk (Chancellor) 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1039338]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2017-06-28 04:30 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (623 votes). Check out past polls.