Skip to content

Instantly share code, notes, and snippets.

@Prajithp
Forked from dex4er/base64.sh
Created January 17, 2018 09:57
Show Gist options
  • Select an option

  • Save Prajithp/7de5f832a71724c5d40dbf9a6ace61d7 to your computer and use it in GitHub Desktop.

Select an option

Save Prajithp/7de5f832a71724c5d40dbf9a6ace61d7 to your computer and use it in GitHub Desktop.
Perl oneliners
# Perl 2 JSON
perl -MJSON -ple '$_=encode_json eval $_'
# JSON 2 Perl
perl -MJSON::PP -MJSON::Syck=Load -MData::Dumper -ple '$_=Dumper(Load(encode_json(JSON::PP->new->relaxed->allow_barekey->decode($_))));'
# MD5 checksum (whole file)
perl -MDigest::Perl::MD5=md5_hex -le 'undef $/; $_=<STDIN>; print md5_hex($_)'
# Encode ASCII string as GSM 7bit string (without charmap conversion)
perl -ple '$l=length($_)*2; $l -= $l>6 ? int($l/8) : 0; $b=unpack("b*", $_); $b=~s/(.{7})./$1/g; $_=sprintf "%02X%s", $l, uc unpack("H*", pack("b*", $b))'
# URL encoding by RFC 3986 (by line)
perl -MURI::Escape -ple '$_=uri_escape($_)'
perl -MURI::Escape -ple '$_=uri_unescape($_)'
# Pretty printing in compact form
perl -MXML::Twig -MText::Wrap -e 'package Text::Wrap; $columns=78; $huge="overflow"; XML::Twig->new(pretty_print=>"indented_c")->parse(\*STDIN)->print;'
# Pretty printing with attributes in separate lines
perl -MXML::Twig -MText::Wrap -e 'package Text::Wrap; $columns=78; $huge="overflow"; XML::Twig->new(pretty_print=>"indented_a")->parse(\*STDIN)->print;'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment