--enable-developer

Brian Candler B.Candler at pobox.com
Mon Nov 5 15:28:01 CET 2012


On Mon, Nov 05, 2012 at 09:41:37AM +0000, Arran Cudbard-Bell wrote:
> Hmm not really equivalent because of the pre-escaping you'd need to do to
> get the string into perl unmolested.  I challenge you to write a one liner
> that'll work with an arbitrary length string from STDIN :P
> 
> Also, I hate Perl, with a passion. Any time I write some I feel dirty, and
> it always comes out looking like someone vomited in the text editor.

In Ruby:

echo "foo\200bar" |
ruby -e 'puts eval("\""+$stdin.read+"\"").unpack("H*").first'

Or without eval:

echo "foo\200bar" |
ruby -e 'puts $stdin.read.gsub(/\\(\d\d\d)/) { $1.to_i(8).chr }.unpack("H*").first'

Note: this will only work on ruby 1.8. Ruby 1.9 has a horrid string encoding
system which requires jumping through hoops to get around.


More information about the Freeradius-Devel mailing list