in reply to OT: What happened to uuencode?

I tried BrowserUK's 1-liner, but it didn't work right for me. I had to set $/=undef. This is what I came up with:

To encode:

#!/bin/sh perl -i.orig -ple'BEGIN{ $/=undef} $_ = pack 'u', $_' $1
To decode:
#!/bin/sh perl -i.uu -ple'BEGIN{ $/=undef} $_ = unpack 'u', $_' $1

Replies are listed 'Best First'.
Re^2: OT: What happened to uuencode?
by Anonymous Monk on Jul 15, 2015 at 15:42 UTC

    Tried to improve it by adding headers:

    #!/bin/sh PATHFILE=$1 SHORTFILE=`basename "$PATHFILE"` perl -i.orig -ple 'BEGIN{$/=undef} $_= "begin 600 $ENV{SHORTFILE}\n". +(pack 'u', $_)."`\nend" if $_' $1
    It can be enhanced by checking the file permissions and setting those too, instead of the hardcoded 600