Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: tinkering with base64 encoding

by sauoq (Abbot)
on Jun 14, 2012 at 21:59 UTC ( #976313=note: print w/ replies, xml ) Need Help??


in reply to tinkering with base64 encoding

So I've written a little script that encodes strings and files in base64. I was a little bored and "I'd rather not install another module for a one-off solution."

I can buy the being bored part.

The part about not installing another module for a one-off solution isn't remotely defensible.

In the time it took to write what you have, and the time you've already spent debugging, and the time you spent writing this node.... you could have installed MIME::Base64 and written

use MIME::Base64; # . . . my $encoded = base64_encode($whatever);
many dozens of times over. I'd certainly rather do that. Especially for a "one-off solution".

-sauoq
"My two cents aren't worth a dime.";


Comment on Re: tinkering with base64 encoding
Download Code
Re^2: tinkering with base64 encoding
by temporal (Pilgrim) on Jun 14, 2012 at 22:15 UTC

    Whoa! By far the most hostile reply that I've ever gotten on PerlMonks.

    Maybe I should add that I also thought I'd learn something by rolling my own.

    Anyway, now that we've established that I'm not so efficient in regard to my use of time - what about my code?

    Strange things are afoot at the Circle-K.

      Whoa! By far the most hostile reply that I've ever gotten on PerlMonks.

      What was hostile about it? I certainly didn't mean for it to be so.

      And you needn't misinterpret my thoughts as a judgment on how you decide to spend your time. It's your time.

      What I was calling into question was your rationale. It would be unfortunate if someone rather less experienced read your well-written node and took away the notion that rolling your own is a good thing to do when you are writing a one-off, especially when exactly the opposite would probably be better advice.

      Maybe I should add that I also thought I'd learn something

      Another fair reason.

      what about my code?

      I haven't looked at it. I'd really just use the two line fix I've already mentioned. ;-)

      -sauoq
      "My two cents aren't worth a dime.";
      I do not think that response was hostile. It just pointed out how to be more efficient. If that hit a touchy spot with you, perhaps the response was indeed correct. :)

      And if you want to have a look at another one's code for doing base64, look at the source for MIME::Base64::Perl.

      It is much more clean and short than your code, mainly because it uses the "u" template in its pack and unpack functions to first encode/decode the data to uuencode standard (which is very close to base64) and then, after doing some cleanup, uses tr to replace the uuencode characters by base64 characters in a one-to-one replacement. Fast, clean and easy to maintain.

      CountZero

      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      My blog: Imperial Deltronics
Re^2: tinkering with base64 encoding
by tobyink (Abbot) on Jun 14, 2012 at 23:34 UTC

    "you could have installed MIME::Base64"

    No need - it's come pre-installed with Perl since version 5.7.3, released over ten years ago.

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
      No need

      That may be too presumptuous. I still run into systems with 5.005_04 (and sometimes older) on them.

      -sauoq
      "My two cents aren't worth a dime.";

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://976313]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (18)
As of 2014-07-11 14:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (227 votes), past polls