in reply to Matching a truncated word

Match the other way around:

perl -le '$x = shift; print 1 if $x and "foobar" =~ /^\Q$x/'

update: added a first test to stop empty $x's from matching (thanks Sifmole), and a \Q in the regex as per the Perl Cookbook. Also note that in Real Life I would of course say 'foobar' and not "foobar", but that's neither here nor there.

--
g r i n d e r

Replies are listed 'Best First'.
Re: Re: Matching a truncated word
by Sifmole (Chaplain) on Jul 31, 2001 at 21:40 UTC
    Minor nitpick, you will test true for the empty case which is not correct.
A reply falls below the community's threshold of quality. You may see it by logging in.