in reply to substr odd behavior with list arguments

That's because prototype(\&CORE::substr) is $$;$$. It means each argument is evaluated in scalar context, so in the second case @a is interpreted as scalar @a, i.e. the size of the array, which is 2.


my ($offset, $length) = a_subroutine_call_that_returns_offset_and_leng +th(@some_args); substr('abcdefg', $offset, $length);

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

Replies are listed 'Best First'.
Re^2: substr odd behavior with list arguments
by wfischer (Novice) on Mar 22, 2021 at 16:26 UTC
    That's the "why" -- thanks for that clear explanation. (And, yes, that's the workaround I use.)