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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.