How Well Can You Read Documentation?

(I was going to call this post “How well do you understand context?” but I think this title is more accurate).

I just saw someone recommending this code:

Looks sensible enough, doesn’t it? But it isn’t. What’s the hidden inefficiency?


Posted

in

by

Comments

7 responses to “How Well Can You Read Documentation?”

  1. David Dorward Avatar

    And now I’ve learned something new about reverse. Hooray for DWIM.

  2. Lars Balker Avatar

    Huh.

    I don’t think that’s a sane behaviour for reverse in scalar context (only ever used it with a single argument in scalar context), but I’ll be damned if I can come up with a better alternative.

  3. Conor Avatar
    Conor

    Why not just: $reversed = scalar reverse $string; ?

    1. Dave Cross Avatar

      Well, quite.

      Although your call to scalar is unnecessary.

      1. Ludo Avatar
        Ludo

        Why does reverse $string return the original string, but an assignment e.g. : $reversed = reverse $string store the reversed string in the lvalue?

        1. Dave Cross Avatar

          As the title implies, read the documentation.

  4. jvector Avatar
    jvector

    late joining the party. SOme of these ‘dwimminess’ features make me a bit uncomfortable. I feel that if c gives me ‘fred’ then maybe it’s not very /useful/, but at least it’s consistent with my simple user model of the language. When convenience measures like making that result be ‘derf’ are mixed into the language, then it seems to me kind of like encountering an irregular verb in a natural language: it may make life easier on this one occasion for somebody but the whole edifice gets just a bit more complicated … adding to the meme that Perl is ‘too hard’.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.