Nice :). Your post inspired me to try something with Lvalue subroutines, I think this works quite well:
use v5.20; use Operator qw{in}; use Variables qw{X Y Z}; my @list = 1..10; (X, Y) = (1, 11); say X." in @list" if X in @list; say Y." not in @list" unless Y in \@list; Z = 'A'; say Z." in list" if Z in ['A'..'C'];
package Variables; use v5.20; our %V; sub import { shift; my $package = caller; no strict "refs"; for my $var (@_) { *{"$package::$var"} = sub:lvalue { @_ ? $_[0]->($V{$var}) : $V{$va +r} }; } } 1;
package Operator; use v5.20; use List::Util qw{any none}; use Exporter 'import'; our @EXPORT_OK = 'in'; sub in(+) { my $list = shift; return sub { any { $_ eq $_[0] } @$list }; } 1;
1 in 1 2 3 4 5 6 7 8 9 10 12 not in 1 2 3 4 5 6 7 8 9 10 A in list
Edit: fixed the broken link for lvalue subroutines thanks to shmem.
Edit: $V{$var} is what I meant, not $V::{$var}
In reply to Re^2: Create a new operator, get LHS (indirect method)
by Eily
in thread Create a new operator, get LHS
by stevieb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |