in reply to Hash versus chain of elsifs

Just use a hash is my routine advice - both for clarity and performance. See also Perl Best Practices (Chapter 6) (O'Reilly) (or Perl Best Practices (squirrel pdf)):

If performance is critical, you could always benchmark different approaches - see Fastest way to lookup a point in a set for a simple example of this.

Oh, and don't use Switch! :)

Replies are listed 'Best First'.
Re^2: Hash versus chain of elsifs
by mldvx4 (Hermit) on Nov 22, 2021 at 11:37 UTC

    The squirrel PDF of best practices you point to is quite interesting. Some I already practice, some are new, others I need more clarification on. Is there a page with more detail on some of the enumerated items, maybe with simple examples for some of them?

      You're meant to buy the book Perl Best Practices from O'Reilly ... though you could try clicking on "Start your free trial". It's considered unethical to search the internet for free pirated PDFs. :)

      TheDamian is a brilliant writer and it's a fantastic book IMHO - where it was described by Yanick as "worth it's weight in depleted uranium bars, and twice as entertaining".

        Thanks. It was not clear that it is part of a book. I'll try to find if there is a bookstore that is not yet part of Amazon. :/

        Perl Best Practices.
        Damian Conway.
        O'Reilly Media, Inc.
        ISBN: 9780596001735