in reply to Empty pattern in regex

Hello choroba,

I don't like to give up without exhausting all avenues of research, and for me Perl is enjoyment and therapy (needed in this world we live in, and this age). This issue may now have dropped off the radars of the other participants, but not mine. jo37 came up with:

perl -le 'print for a .. h' | perl -nle 'if (my $ff = (/d/ .. /h/)) { +next unless $ff =~ /(?:^1|E0)$/; print }' d h

which troubles me because of that alternation and the absence of //, which I think is/was your point. Mine are, granted, after debugging with strategic print statements:

perl -le 'print for a .. z' | perl -nle 'if (/d/ .. /h/) { next unles +s // and $_ eq $&; print; }' d h

or

perl -le 'print for a .. z' | perl -nle 'if (/d/ .. /h/) { next unles +s $_ eq $& and //; print; }' d h

and is a short-circuit operator so it works either way. Does this do what you expected it to do?

Regards, Will

Replies are listed 'Best First'.
Re^2: Empty pattern in regex
by jo37 (Curate) on Oct 23, 2023 at 18:04 UTC

    It was not my intention to cause any troubles. $ff =~ /(?:^1|E0)$/ can be rewritten as $ff == 1 || $ff =~ /E0$/. When the second operand of the flip-flop operator becomes true, the return value gets an E0 appended. This does not change the value in numeric context as it is just one of its floating point representations. In string context it is distinguishable from all the other values, though.

    HTH

    Greetings,
    -jo

    $gryYup$d0ylprbpriprrYpkJl2xyl~rzg??P~5lp2hyl0p$
Re^2: Empty pattern in regex
by choroba (Cardinal) on Oct 23, 2023 at 17:52 UTC
    The $_ eq $& is an interesting idea. Note that it only works because of -l, otherwise \n would have been included in $_ but not $&.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]