On 2023-04-03 20:50:22 -0700, Will Mengarini wrote: > * cor...@free.fr <cor...@free.fr> [23-04/04=Tu 10:35 +0800]: > > For instance, in ruby (irb) this is quite smooth: > > irb(main):001:0> [1,2,3,4].map{|x|x+1}.reduce{|x,y|x+y} > > => 14 > > > > And in scala (shell): > > scala> List(1,2,3,4).map{ _+1 }.reduce{_+_} > > res1: Int = 14 > > > In perl there is no interactive shell [...] > > perl -le 'print eval $_ while <>'
https://metacpan.org/pod/Shell::Perl https://stackoverflow.com/questions/73667/how-can-i-start-an-interactive-console-for-perl TIMTOWTDI :-) > > In perl [...] the block statement seems strange: > > $ perl -le '@x=(1,2,3,4); $sum+=$_ for( map {$_+1} @x );print $sum' > > 14 > > perl -le '@x=(1..4); print eval join "+", map $_+1, @x' Though I have already used the eval+join trick a few years ago, this is rather ugly. Using List::Util with "reduce" is probably better: https://metacpan.org/pod/List::Util -- Vincent Lefèvre <vinc...@vinc17.net> - Web: <https://www.vinc17.net/> 100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/> Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)