Search code examples
perlstdinpackunpack

Perl pack, unpack and STDIN


Can someone explains me why this is not working as I expect it?

zen:~ emx$ echo ABC | perl -nle "print unpack 'H*'"
414243
zen:~ emx$ echo 414243 | perl -nle "print pack 'H*'"

zen:~ emx$

Somehow I was expecting the second command to print ABC


Solution

  • unpack() uses $_ by default if you do not provide it with a second parameter; pack() on the other hand, does not.