Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

another easy question here: I am too dumb to figure out the syntax for a pattern match of substrings. For example, I need: Bill to be seen in a textline of Billiard. Thanks ahead for your help!
if ($line =~ /$partialword/i){ #SUBSTRING FOUND! }

Replies are listed 'Best First'.
Re: substr pattern matching
by PetaMem (Priest) on May 03, 2002 at 15:52 UTC
    I don't know where your problem is. This piece of code works:
    my $line = 'Billard'; my $partialword='bill'; if ($line =~ /$partialword/i){ print "SUBSTRING FOUND!\n"; }

    Bye
     PetaMem

(jeffa) Re: substr pattern matching
by jeffa (Bishop) on May 03, 2002 at 16:02 UTC
    Hmmmm ... are you possibly wanting the index function?
    use strict; my $string = "Billiard"; if (index($string,'Bill') > -1) { print "found it!\n"; }
    This is not a pattern match, however ... looks like your code should work fine.

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
Re: substr pattern matching
by vek (Prior) on May 03, 2002 at 15:55 UTC
    Having a hard time understanding exactly what you mean so I'm going to make a big assumption here. I'm thinking that you have a string 'Billiard' and you want to change that to 'Bill':
    if ($line =~ /$partialword/i) { # I'm assuming $partialword is 'Bill'... $line =~ s/Billiard/Bill/; }
    -- vek --