in reply to Macro-envy, a snippet.

So why all the @foo_attributes arrays instead of an %attributes HoA? And don't forget ->$method syntax.

Replies are listed 'Best First'.
Re^2: Macro-envy, a snippet.
by diotalevi (Canon) on Feb 20, 2006 at 07:58 UTC
    So why all the @foo_attributes arrays instead of an %attributes HoA?

    I got strict to check my names for me - that wouldn't happen with hash keys. It's also cheaper to use. I use ->$method syntax when forced to but it's verbose. It requires two statements where I previously had one expresssion.

    my $m = "stringify_%1$s"; $self->$m( $op, $_ )

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

      You can roll these into a single expression, as I posted in direct reply: $self->${ \"stringify_$foo" }( $op, $_ )

      Makeshifts last the longest.

      Previously, you had one expression and a macro (that was probably defined a long way away). If you're optimizing for the count of the number of expressions, I think you're doing it wrong.

      --
      brian d foy <brian@stonehenge.com>
      Subscribe to The Perl Review

        I'd rather have an anonymous macro there. It only needs a name if I'm going to do it multiple times or if it's distracting to have inline.

        ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

      Hash::Util (in the core in Perl 5.8) has routines to lock hashes. Sure, it happens at run time rather than compile time. But still I've found it to be very useful when developing software.