Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
When I began learning Perl, almost exactly 6 years ago, it was so much fun that I couldn't get enough of learning new things.  I had bought Learning Perl, vol. 2, a couple of years earlier, but hadn't made much of a dent in it, mostly because I wasn't involved in actually using it for any programming.  So just reading about it was doomed to failure, in retrospect.

But in the summer of 2000, I was using it for work, and loving the process.  The book "Learning Perl" (and several other newly-acquired Perl books as well) now became not only useful, but a source of new learning and fresh inspiration each time they were opened.  It even became a habit to read chapters from Perl books in my spare time, just to learn all the cool constructs I had never encountered in any other languages.  I still remember the excitement I felt discovering for the first time about tied variables.  Or grasping the beauty of data structures which behaved one way in scalar context, and another way in list context, and the sheer beauty and logic of such a system.  Or the intricate wealth of reusability that came from writing object-oriented modules.

And of course, the plethora of functions!  Every time I researched this still-new (to me) language, there were all the functions that I loved in C, and new ones everywhere I looked.  Add to that the complex user-defined data structures, sophisticated regular expressions, elaborate subroutine closures ... "Swiss-army Chainsaw" didn't even begin to describe the power!

But I have to admit I don't spend the same long hours reading about Perl the way I used to.  I'm sure it's a common phenomenon for many; you look up what you need, when you need it, and that's about all.  I did recently purchase Mark Jason Dominus' book, "Higher Order Perl", and although it's a fascinating and thoroughly illustrative book, I confess that I only read maybe 10-20 minutes of it at a time, not the 2-3 hours that I used to spend entrenching myself in learning.  One gets to a point, perhaps, where it one feels that they know essentially all of the basics; no more big surprises when it comes to the fundamentals.

So it was today that I surprisingly came across something simple that I realized I didn't know how to do.  While writing a program to demonstrate the application of the Bailey-Borwein-Plouffe formula, I couldn't figure out how to to convert a very long string, containing a binary value, into a hexadecimal value.  I knew about hex and oct, but there isn't a bin equivalent, and though sprintf will output in binary, there wasn't an obvious way to make Perl treat my string as binary on input.  

When I came across the answer, I realized I had missed something basic, back when I was just starting out with Perl.  The oct function can work with a variety of input bases (not just octal), by specifying the base at the front:

0xN .... interpret N as hexadecimal 0bN .... interpret N as binary N .... interpret N as octal

And the oct documentation even suggests a method of handling any of the common 4 bases, with:

The following will handle decimal, binary, octal, and hex in the standard Perl or C notation: $val = oct($val) if $val =~ /^0/;

So now I'm wondering what other basics I may have missed along the way, either because I never noticed them the first time through, or just didn't need to know them until now.

And I'm curious, and ask the question of you, my brethren:  "What basic function, construct, or concept in Perl did you recently learn, that you were surprised to find you hadn't already known?"


s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

In reply to What I Most Recently Learned in Perl, But Should Have Already Known by liverpole

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (8)
    As of 2014-09-02 07:50 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite cookbook is:










      Results (20 votes), past polls