I had need for a new #perl operator today, like:

$val //~ s/$prefix//;

that would be equivalent to:

$val =~ s/$prefix// if defined $val;

is it too late to get this for v5.42 ?

#notdeadyet #morelinenoise @Perl

@Perl some people were taking this more seriously than I intended- it’s all good!.
I agree the syntax I suggested could pose multiple problems. If anyone is still thinking about it, then &&~ would be better, avoids those problems. #perl
@Pyrrhlin @Perl I suspect yes for 5.42, no for 5.44
@Pyrrhlin @Perl cannot do that since // (~s///) would need to be deprecated first.
there are proposals for a more generic =~:u though

@Pyrrhlin @Perl
I think it would also be equivalent to:

{ no warnings 'unintitialized';
$val =~ s/$prefix// }

Or am I missing something here?

This seems more like a code smell to me. If you need to preprocess the content of the scalar, is it warranted for the scalar to still be potentially undef afterwards?

Beware: The seemingly similar '//=' operator does assign something only if the scalar is NOT defined. Your proposed operator would do something only if the scalar IS defined.

@Pyrrhlin @Perl How about this instead of the postfix `if`?

defined $val and $val =~ s/$prefix//;

@mjgardner @Perl also good. #timtowdi my friend!
why do i prefer postfix `if`? hmm.
maybe the conditional `and` with a statement (rather than a test) feels like `map` in void context, which also feels a little icky

@Pyrrhlin I do it all the time for cheap regexp-based switches, as described in perlfaq7: https://perldoc.perl.org/perlfaq7#How-do-I-create-a-switch-or-case-statement?

```
SWITCH: for ($pizza) {
/pepperoni/ and do {say 'yum!'; last SWITCH};
/anchovies/ and do {say 'yuck!'; last SWITCH};
}
```

perlfaq7 - General Perl Language Issues - Perldoc Browser

@mjgardner sure. I use the low-precedence boolean ops in some conditional test where i also want/need to set/topicalize a lexical var.
for your switch construct, i'd use the trailing `if` again :)

@Pyrrhlin I like to see the test first when reading from left to right.

Per #perlcritic I reserve postfix controls for program flow control functions like return, last, next, etc. https://metacpan.org/pod/Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls

Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls

Write if($condition){ do_something() } instead of do_something() if $condition.

MetaCPAN