M
mmasroorali
Dear All,
Below is a minimal version of my code. I want to check whether all the
elements of an array are contained in another array. Sounds fairly
simple, but somehow one is not being found. The second line of output
should also be a Match, which is not as you can see.
Could anybody please tell me what is it I am missing. I have ran
everything through ptkdb without a clue.
Regards.
#!/usr/bin/perl
use strict;
use warnings;
use Text:arseWords;
my $f;
my $inputline = '"a, b", c, d';
my $flag = "a,b";
# Separate flags into a list of tokens
my @flag = split(/,/,$flag);
# Get the flag part from input line
(my $inputflags, my $rest) = quotewords(",", 0,$inputline);
# Split the flags into an array and convert them to a hash for
# faster lookup
my @inputflags = split(",", $inputflags);
my %ininputflags = ();
for (@inputflags) { $ininputflags{$_} = 1;}
# Check if all of the flags are contained the in the input line flag
field (first field)
for $f(@flag)
{
if ($ininputflags{$f})
{
print "Match for $f in inputflags:\n";
}
else
{
print "Unmatch for $f in inputflags:\n";
}
}
OUTPUT
Match for a in :a b:
Unmatch for b in :a b:
Below is a minimal version of my code. I want to check whether all the
elements of an array are contained in another array. Sounds fairly
simple, but somehow one is not being found. The second line of output
should also be a Match, which is not as you can see.
Could anybody please tell me what is it I am missing. I have ran
everything through ptkdb without a clue.
Regards.
#!/usr/bin/perl
use strict;
use warnings;
use Text:arseWords;
my $f;
my $inputline = '"a, b", c, d';
my $flag = "a,b";
# Separate flags into a list of tokens
my @flag = split(/,/,$flag);
# Get the flag part from input line
(my $inputflags, my $rest) = quotewords(",", 0,$inputline);
# Split the flags into an array and convert them to a hash for
# faster lookup
my @inputflags = split(",", $inputflags);
my %ininputflags = ();
for (@inputflags) { $ininputflags{$_} = 1;}
# Check if all of the flags are contained the in the input line flag
field (first field)
for $f(@flag)
{
if ($ininputflags{$f})
{
print "Match for $f in inputflags:\n";
}
else
{
print "Unmatch for $f in inputflags:\n";
}
}
OUTPUT
Match for a in :a b:
Unmatch for b in :a b: