KurtZ has asked for the wisdom of the Perl Monks concerning the following question:

Hi

New colleague is struggling with Perl context and I remember seeing once an tabular overview of builtins and their corresponding return values.

Could you help me find it again?

Looked into perlfunc and found only dispersed references.

Hoping for a something like perlcheat grouping similar cases together.

Replies are listed 'Best First'.
Re: Overview scalar vs list context?
by ikegami (Patriarch) on May 21, 2017 at 09:06 UTC
      Awesome, thank you! :)
Re: Overview scalar vs list context?
by Your Mother (Archbishop) on May 20, 2017 at 21:19 UTC

    I think I saw something like that but I can’t think of where or the context… har-har-har. There is this Context tutorial at least for now.

Re: Overview scalar vs list context?
by oldtechaa (Beadle) on May 21, 2017 at 02:36 UTC
Re: Overview scalar vs list context?
by kcott (Archbishop) on May 21, 2017 at 07:16 UTC

    G'day KurtZ,

    "... overview of builtins and their corresponding return values."

    Many functions return different values based on their context. A couple of examples:

    $ perl -E 'say grep $_ => (0,1,1,1); say scalar grep $_ => (0,1,1,1)' 111 3 $ perl -E 'say localtime; say scalar localtime' 51491621411701400 Sun May 21 16:49:51 2017

    So there isn't a one-to-one mapping between functions and return values. The important issue is to understand context itself. See "perldata: Context". Sorry if that sounds a bit blunt; however, without knowing in what way your "colleague is struggling", it's difficult to provide more specific help.

    I don't recall ever seeing the "tabular overview" you mentioned.

    "Looked into perlfunc and found only dispersed references.."

    Yes, that's a large and unwieldy beast: I almost never use it! You may find the "Perl functions A-Z" is a lot easier to reference functions and find how they operate in different contexts: I use this regularly.

    — Ken

Re: Overview scalar vs list context?
by shmem (Chancellor) on May 20, 2017 at 18:28 UTC
    Looked into perlfunc and found only dispersed references.

    Condense them:

    man perlfunc | perl -n00 -le 'print if /scalar/' | less
    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
      Are you joking?
        Are you joking?

        That would be best, I admit. But sadly, no. I don't have any tabular data on context driven behavior of builtins, so sorry.
        But filtering that way gives a rough overview of context sensitive builtins, which should suffice for teaching purposes.
        Anyways there is no way around reading all of perlfunc. All of it.

        update:

        Since

        New colleague is struggling with Perl context

        and context sensitivity is a fundamental concept of the Perl language, a cheat sheet would be of no help whatsoever, period.

        perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'