I did the 'in' function for seeing if one element is inside on list like.
sub in {
my $match = shift;
foreach (@_) {
return 1 if $match eq $_;
}
return 0;
}
so I'm calling the function like
if(in($x => (1,2,3))) {
...
};
this seems to be nice. After this I sink: why not to write
if ($x in (1,2,3)) {
...
}
So I create one module like:
package MyFilter;
use Filter::Simple;
use vars qw (@ISA @EXPORT @EXPORT_OK);
require Exporter;
push(@ISA, qw(Exporter));
@EXPORT_OK = qw(in);
FILTER_ONLY code => sub {
my $ph = $Filter::Simple::placeholder;
s/(((\$[a-zA-Z_0-9]+)|\-?[0-9]+(\.[0-9]+)?|$ph))\sin\s/in $1, /g;
};
sub in {
my $match = shift;
foreach (@_) {
return 1 if $match eq $_;
}
return 0;
}
1;
And this test script
use MyFilter qw (in);
my $xxx = "a";
if (4 in (2,3,4,5,6,7)) {
print "OK\n";
} else {
print "OPS\n"
}
if ($xxx in (2,3,"b",5,"vvvv",7)) {
print "OK\n";
} else {
print "OPS\n"
}
print('$xxx in 2, 3 : ', ($xxx in 2, 3), "\n");
print('"b" in (2, 3) : ', ("b" in (2, 3)), "\n");
print('4 in (2,3,4,5,6,7) : ', (4 in (2,3,4,5,6,7)), "\n");
print('3.2 in 2, 3 : ', (3.2 in (2, 3)) , "\n");
print('in ($xxx => "a", 5) : ', in ($xxx => "a", 5) , "\n");
This seems to work.
Can someone test some more and give some bugs?
Is there a generic module for doing operators?
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>