Re: golfing one liner
by haukex (Archbishop) on Mar 02, 2019 at 09:45 UTC
|
$ perl -E 'say join$",a..z'
a b c d e f g h i j k l m n o p q r s t u v w x y z
$ perl -E 'say"@{[a..z]}"'
a b c d e f g h i j k l m n o p q r s t u v w x y z
Update: Added second version (~1 min after posting :-) ) | [reply] [d/l] [select] |
|
|
$ perl -E '$,=$";say a..z'
a b c d e f g h i j k l m n o p q r s t u v w x y z
| [reply] [d/l] |
|
|
print "from 'a' to 'z':\n";
do { local $, = $"; print a..z };
| [reply] [d/l] |
|
|
| [reply] |
|
|
Bingo! You da man!
Prefer first version!
| [reply] |
Re: golfing one liner
by Laurent_R (Canon) on Mar 02, 2019 at 10:08 UTC
|
haukex's solutions are probably better (and my first thought when reading your post was to use join in something very similar to haukex's first solution), but you could also use map:
$ perl -E 'say map "$_ ", a..z'
a b c d e f g h i j k l m n o p q r s t u v w x y z
Update at 10:30 UTC: I had not seen that you said in the title that you wanted a golfed solution. You can just remove some spaces to improve the character count:
$ perl -E 'say map"$_ ",a..z'
a b c d e f g h i j k l m n o p q r s t u v w x y z
| [reply] [d/l] [select] |
|
|
Excellent - many thanks! Great book btw - I have already seen it...
| [reply] |
Re: golfing one liner
by karlgoethebier (Abbot) on Mar 02, 2019 at 11:21 UTC
|
In for a penny, in for a pound (if that really means "Wenn schon, denn schon"): perl -E 'map {say} a..z'
Regards, Karl
«The Crux of the Biscuit is the Apostrophe»
perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help
| [reply] [d/l] [select] |
|
|
Woa! That takes the biscuit for being ultra-coincise - and the say does one per line rather than all one same line - however now they are not separated by spaces - I do not even understand that incantation!
| [reply] |
|
|
perl -E 'map {say} a..z'
perl -E 'map say, a..z'
perl -E 'say for a..z'
perl -E 'say a..z' # All joined.
| [reply] [d/l] |
Re: golfing one liner
by choroba (Cardinal) on Mar 02, 2019 at 23:06 UTC
|
The bash answer is even shorter than any Perl one-liner:
echo {a..z}
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
| [reply] [d/l] [select] |