in reply to Why does this happen?

There's a few problems, which some have touched on. However, what if I typed in a sentence for an insult? It wouldn't match if I used "disk" in a sentence, eh?

Try this instead:

#!/usr/bin/perl -w use strict; print "What is your insult? "; chomp(my $input = <>); my @matching = qw/disk duck deck/; foreach $j (@matching) { die "bastard\n" if($input =~ /$j/); }
Hmmm... can't we precompile these three items, incase they're used often?

--
$Stalag99{"URL"}="http://stalag99.keenspace.com";

Replies are listed 'Best First'.
Re: Re: Why does this happen?
by grinder (Bishop) on Apr 04, 2001 at 12:36 UTC

    You could compile them into a regexp with

    my $re = do { local $"='|'; qr/^(?:@matching)$/ };

    --
    g r i n d e r