Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Perl Substr

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

Comment on Re: Perl Substr
Download Code
Replies are listed 'Best First'.
Re^2: Perl Substr
by AnomalousMonk (Canon) 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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (16)
As of 2016-02-12 17:23 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (410 votes), past polls