perlsyntaxsubroutinechr

use function names in perl's map


I was playing with this piece of code to print a list of chars:

perl -e 'print join(" ", map { sprintf "%02x", ord }  grep /\s/, map { chr } 0x0 .. 0x7F )'

Is there a easier way to write map { chr } 0x0 .. 0x7F ?

I've tried:

map \&chr 0x0 .. 0x7F

But I get syntax error.


Solution

  • map { chr } 0x00 .. 0x7F is already pretty concise, but in addition to the map BLOCK LIST syntax, there is also the map EXPR,LIST syntax.

    map chr,0x00..0x7f
    map chr,0..127