How to use perl’s uri_encode in one line
html, html-entities, macos, perl
Solution
Try doing this using the proper module =)
$ echo 'one two' | perl -MURI::Escape -wlne 'print uri_escape $_'
one%20two
See URI::Escape doc
Note
If you need something faster, consider using URI::Escape::XS
Problem
In the past I’ve used the code `echo "<one two>" | perl -MHTML::Entities -ne 'print decode_entities($_)'` to output `<one two>`. Now I want to do something similar, but I want to encode it in a way that `echo "one two" | *perl magic*` outputs `one+two`, or maybe `one%20two`. I’d like a command that’d do this kind of url encode on the whole string, that could be piped, like the first example.