Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Perl Substr

by BillKSmith (Chaplain)
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
Re^2: Perl Substr
by AnomalousMonk (Monsignor) 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 meditating upon the Monastery: (12)
As of 2014-08-28 15:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (263 votes), past polls