Re: my immature thoughts on perl
On Tue, Apr 04, 2023 at 10:35:39AM +0800, coreyh@free.fr wrote:
> 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
And Tcl:
unicorn:~$ rlwrap tclsh
% ::tcl::mathop::+ {*}[lmap x {1 2 3 4} {expr {$x+1}}]
14
As long as we're collecting solutions.
> In perl there is no interactive shell, and the block statement seems
> strange:
>
> $ perl -le '@x=(1,2,3,4); $sum+=$_ for( map {$_+1} @x );print $sum'
> 14
I'm not as experienced with perl. I don't know how to shorten that.
Reply to: