Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: regex and substrings

by sundialsvc4 (Abbot)
on Jul 23, 2018 at 18:29 UTC ( [id://1219128]=note: print w/replies, xml ) Need Help??


in reply to regex and substrings

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^2: regex and substrings
by marto (Cardinal) on Jul 23, 2018 at 18:43 UTC

    Doesn't even compile:

    Bareword found where operator expected at derp.pl line 7, near "// to" (Missing operator before to?) "my" variable $str2 masks earlier declaration in same scope at derp.pl + line 8. "my" variable $str1 masks earlier declaration in same statement at der +p.pl line 9. "my" variable $str2 masks earlier declaration in same statement at der +p.pl line 9. syntax error at derp.pl line 7, near "// to auto" Execution of derp.pl aborted due to compilation errors.

    You pontificate about the language about testing, you don't even know how to comment perl code. This is not the first time you've done this.

Re^2: regex and substrings
by AnomalousMonk (Archbishop) on Jul 23, 2018 at 19:43 UTC
    ... (Perl >= 5.16) ...

    Ignoring the fact that I don't understand the meaning of the quoted bit, and sidestepping the foreign comment operator, it compiles and does what ovedpo15 seems to want. On the whole, a bucketful out of the boat, so an upvote from me. (Now please, please don't negate this with a dozen bucketsful back into the boat!)


    Give a man a fish:  <%-{-{-{-<

      I know you're just trying to help; I think it's water on a duck. What ensures the downvote from me is that he could edit the node to fix the comment and mark it with (Update: fixed comment character). It's trivial to improve the monastery with these tiny bits of effort. It's what us “self-important pricks” do on a daily basis.

        ... water on a duck.

        Sadly, I'm starting to agree.


        Give a man a fish:  <%-{-{-{-<

Re^2: regex and substrings
by Marshall (Canon) on Jul 24, 2018 at 19:21 UTC
    I like the solution from jeffenstein++

    Regex will be slower than the above solution.
    I would code a regex version like this:

    #!/usr/bin/perl use strict; use warnings; my $str1 = "helloworld"; my $str2 = "hello"; if ($str1 ne $str2 and $str1 =~ /\Q$str2\E/) { print "yes, $str2 is a substring of $str1\n"; } # Note: the \Q and \E escapes are not needed in # this exact situation. These escape characters mean # to ignore any chars in $str2 that might otherwise # mean something to the regex engine. # In this simple case the \E is not needed, but # I would recommend a \Q...\E pair. __END__ Prints: yes, hello is a substring of helloworld

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-25 23:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found