Join Map Ord Split
Just when you thought Perl couldn't get more unreadable, someone[0] comes up with something like this:
print join ", ", map ord, split //, $foo;
This mess of perl might be easier to understand if I put the brackets in:
print join (", ", map( ord, split( //, $foo)));What this does is split $foo into a list of characters. It then uses map to run ord() on each item in the list to return a new list containing the numeric character values. We then join these again with ", " to make the output easier to read.
david% perl -e 'print join ", ", map ord, split //, "word";' 119, 111, 114, 100
The map function is familiar to functional programmers and is very powerful, but beware it can reduce the clarity of your code.
[0] Me