0

I need to match a string against an array of strings. The string that I am searching for should be able to contain wildcards.

#!/usr/bin/perl
#
##   disable buffered I/O which would lead
##   to deadloops for the Apache server
$| = 1; 
#
##   read URLs one per line from stdin
while (<>) {
    my $line = $_;
    my @array1 = ("abc","def","ghi");
    $found = 0;
    if (/$line/i ~~ @array1)
    {
        print "found\n";
    }
    else
    {
        print "not found\n";
    }

}

I test this script with the input of abc and it returns not found

perl ./mapscript.pl
abc
not found

3 Answers 3

3

Your input has a newline at the end. Add:

chomp $line;

right after

my $line = $_;
Sign up to request clarification or add additional context in comments.

Comments

2

Use chomp(my $input = $_) to remove newline instead of my $input = $_ inside your while..

** OOPs.. Didn't see that I'm posting Duplicate..

Comments

1

a newline at the end always exists using <>. see chomp

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.