in reply to get string/array slices using cut-like specifications
Alright, now let's get started with a#!perl -lp BEGIN { $s = shift } sub cut { my ($s, $r) = pop; for (split /,/, shift) { $r .= /(\d+)-(\d+)/ ? substr $s,$1-1,$2-$1+1 : substr $s, $_-1 +,1; } $r; } chomp; $_=cut $s, $_;
...or 73:#!perl -lp BEGIN{@s=split/,/,shift} chomp; $x=$_; /(\d+)-?/, $r.=substr$x,$1-1,($'||$1)-$1+1 for@s,$r=''; $_=$r
#!perl -ln BEGIN{($s=shift)=~s/-/../g} chomp; $x=$_; print+map{substr$x,$_-1,1}eval$s
|
|---|