Proof of concept

#!/usr/bin/perl -- BEGIN{ package PPI::Transform::ConditionalAssignment; use strict; use warnings; use Params::Util qw{_STRING _INSTANCE}; use PPI::Transform (); use parent 'PPI::Transform'; our $VERSION = '0.1'; # VERSION sub document { my $self = shift; my $document = _INSTANCE(shift, 'PPI::Document') or return undef; my $elements = $document->find( sub { $_[1]->isa('PPI::Token::Operator') or return ''; $_[1]->content eq '?' or return ''; $_[1]->snext_sibling->isa('PPI::Token::Operator') or return '' +; $_[1]->snext_sibling->content eq '=' or return ''; return 1; } ); return undef unless defined $elements; return 0 unless $elements; my $changes = 0; foreach my $question ( @$elements ) { my $symbol = $question->sprevious_sibling->clone; my $equals = $question->snext_sibling; $equals->insert_after( $symbol ); $symbol->insert_after( $question->remove ); $changes++; } return $changes; } 1; $INC{'PPI/Transform/ConditionalAssignment.pm'}=__FILE__; } # BEGIN package main; use Filter::PPI::Transform 'PPI::Transform::ConditionalAssignment'; for my $foo ( 0 .. 1 ) { my $bar = $foo; $foo ?= 'one' : 'zero'; print "$foo\n"; $bar ?= ('one '.rand): ('zero '.rand); print "$bar\n"; } print "let me know " ? "should I stay" : "or should I go"; __END__ $ perl ppi-transform-conditional-assignment.pl zero zero 0.563323974609375 one one 0.086761474609375 should I stay

In reply to Re^2: RFC: "assignary" operator ?= : ( use Filter::PPI::Transform 'PPI::Transform::ConditionalAssignment'; ) by Anonymous Monk
in thread RFC: "assignary" operator ?= : by richard.sharpe

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.