Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Perl mnemonics

by missingthepoint (Friar)
on Oct 07, 2008 at 14:12 UTC ( #715796=perlmeditation: print w/replies, xml ) Need Help??

Greetings, monks.

Since the question tacked on to the end of my post here hasn't got any bites yet, I thought I'd bring it up here, where it's on topic. (And visible; I for one don't read Perl Poetry that often...)

In the aforementioned post I shared a (somewhat silly) mnemonic for remembering the structure of a printf() conversion specifier (the bit from the percent to the conversion type character, inclusive).

So, the question: have any of you come across or devised Perl mnemonics? There seems a notable dearth of nodes here on this. I like the idea - for me it means reciting a quick poem or phrase instead of spending 5 minutes skimming POD trying to find what I want. The benefit is not only time saved, it's more Perl knowledge inside your head.

Please share. I just read TheDamian's mnemonic for distinguishing the /s and /m regex switches, and I want more! :)

email: perl -e 'print reverse map { chr( ord($_)-1 ) } split //, "\x0bufo/hojsfufqAofc";'

Replies are listed 'Best First'.
Re: Perl mnemonics
by BrowserUk (Pope) on Oct 07, 2008 at 14:53 UTC
Re: Perl mnemonics
by moritz (Cardinal) on Oct 07, 2008 at 14:37 UTC
    Well, perlvar has some mnemonics, which I found quite useful.
Re: Perl mnemonics
by TGI (Parson) on Oct 07, 2008 at 18:52 UTC

    It isn't strictly perl, but it comes up doing graphics programming. When I need to remember the coordinate order for a box, I use "terrible" and "later babe" to remember whether the elements go in "top, right, bottom, left" or "left, top, right, bottom" order.

    For example, CSS is terrible when you specify borders and margins:

    margin: 1em 2em 3em 4em; // is equivalent to: margin-top: 1em; margin-right: 2em; margin-bottom: 3em; margin-left: 4em;

    TGI says moo

      Nice. In Cascading Style Sheets: The Definitive Guide, Eric Meyer uses 'TRouBLe' for that.

      The same book also has 'LoVe, HA!' for the source order of common pseudo-classes (link, visited, hover, active).

      email: perl -e 'print reverse map { chr( ord($_)-1 ) } split //, "\x0bufo/hojsfufqAofc";'
      I have to think of a clock to remember which order CSS properties go in.

      The day starts at midnight, when the minute hand points up, or towards the top of the object. As the day progresses, the hand moves clockwise around, and points towards the right, then the bottom, then the left.

      I spent quite a long time flipping through my CSS book when I needed to do something until I thought of that - I don't really work with CSS often enough that I could just memorize the order and know it without some help.

        "Terrible" stuck for me because I was having a terrible time remembering the order. And it was the first meaningful mapping I came up with.

        I am in awe of your power of observation. I never noticed that the ordering went clockwise--a note in the docs somewhere to that effect would have saved me thousands of reference book pages flips and hundreds of google queries over the years.

        TGI says moo

Re: Perl mnemonics
by zentara (Archbishop) on Oct 07, 2008 at 16:01 UTC
    Like dragonchild, I go with the mental picture is worth a thousand words. I never was good at remembering poems, limericks, or jokes; but I can pull an image out of my memory easily. Also, If you are not actually cramming for a closed book test, why not just take a quick look at some code snippets (either in your personal snippet lib or search

    However, there was one recently that I do use, regarding the packing rules in Gtk2, which I just can't seem to get straight without looking at previous examples.

    $vbox->pack_start ($widget, $expand, $fill, $padding);
    it's the expand, fill, padding order that always gets me. So I remember

    "extra fries please";

    I'm not really a human, but I play one on earth Remember How Lucky You Are

      If I did Gtk2 programming, I'd probably call that order "WE FliP".

      The pain of having to remember these orders is why any code I write that requires more than three arguments, gets modified to use named parameters. The downside is that you have to remember (and spell correctly) the parameter names, but that's what perldoc's for.

      TGI says moo

Re: Perl mnemonics
by dragonchild (Archbishop) on Oct 07, 2008 at 14:53 UTC
    I don't remember things that way. Instead, my memory is akin to a photographic memory. I can't read off of the pages in my memory; instead, I have an index into what I've read. So, I know what things have been mentioned in docs, roughly where in the docs they are, etc.

    Of course, this is nearly useless without access to - in the past, I've mentioned that I can never remember the order of the args for splice. :-)

    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

      I'll be damned. I'm the same way. I remember where on the page of a book--e.g., right side, second paragraph, 1/3 into book--I saw something but rarely the page number. There must be a name for this.

        It's the only way I passed history and biology in high school. At the time, I didn't have a way of organizing non-hierarchical data in my head, so I just memorized the book's layout and would use that to job my memory.

        I don't know what it's called. I would also be interested in knowing that. You're the first person I've met whose head works this way as well.

        My criteria for good software:
        1. Does it work?
        2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
Re: Perl mnemonics
by wfsp (Abbot) on Oct 07, 2008 at 15:35 UTC
    The word always reminds me of a footnote in Programming Perl: "If you can't remember what a mnemonic is you're in trouble." :-)
Re: Perl mnemonics
by JavaFan (Canon) on Oct 07, 2008 at 15:58 UTC
    /m Multiple lines /s Single line /i case Insensitive (also grep -i) /x eXtended pattern /e Eval replacement /p Preserve pre- and postmatch /g Global matching /c keep Current position

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://715796]
Approved by wfsp
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2021-11-28 21:31 GMT
Find Nodes?
    Voting Booth?

    No recent polls found