in reply to The cognitive load of generated code

I'm not sure about "production-ready". Why is the filename "0" shortened to undef? ;-)

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

Replies are listed 'Best First'.
Re^2: The cognitive load of generated code
by Anonymous Monk on May 18, 2026 at 16:46 UTC
    I love how much smarter you are than me and that dummy claude choroba! I have a bad habit of avoiding // because it can give me an extra 10 years of backwards compatibility, just in case anyone is still using anything older than v5.10.0. As you've seen, this probably poor decision, makes zero the bane of my existence; but it was a fun minute-long puzzle to fix the bug:
    my $f = defined $_[0] ? shift : return;
Re^2: The cognitive load of generated code
by ikegami (Patriarch) on May 19, 2026 at 01:21 UTC

    Worse, it's shortened to empty list. Returning an empty list from a sub expected to return a scalar can have very weird effects.

    length $f <= $m is awful too. foo $f <= $m normally means foo( $f <= $m ), so seeing length $f <= $m raises red flags, adding to cognitive load. (It's valid, but only because length breaks operator precedence.)

      I see what you mean. The lack of parentheses on length and especially int is ambiguous. I remember having to test int once to see if something like int $a / 2 means int($a) / 2 or int($a / 2) and since it meant the latter I adopted that bad habit. I could probably write a book: Perl Worst Practices! Thanks for the clues.
      sub shortencentered { my $f = defined $_[0] ? shift : return ''; # be less weird :-) my $m = shift || 42; return $f if length($f) <= $m; my $a = $m - 3; my $s = int($a / 2); my $e = $a - $s; return substr($f, 0, $s) . '...' . substr($f, -$e) }