in reply to Re: Macro-envy, a snippet.
in thread Macro-envy, a snippet.

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, $_ )

⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Replies are listed 'Best First'.
Re^3: Macro-envy, a snippet.
by Aristotle (Chancellor) on Feb 21, 2006 at 07:49 UTC

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

    Makeshifts last the longest.

Re^3: Macro-envy, a snippet.
by brian_d_foy (Abbot) on Feb 20, 2006 at 19:23 UTC

    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.

      ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

        If you're only going to do it once, you don't need a macro. It seems to me that you have a solution in search of a problem. If you stop fighting Perl and start working with it, you'll probably have an easier time. :)

        --
        brian d foy <brian@stonehenge.com>
        Subscribe to The Perl Review
Re^3: Macro-envy, a snippet.
by tilly (Archbishop) on Feb 24, 2006 at 04:34 UTC
    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.