in reply to Re: Reading binary files - program structure
in thread Reading binary files - program structure

I think would prefer to use subs rather than string eval here. Eg.

my %varlengths = ( 'that' => sub(){ 2 }, 'theother' = sub{ $v{this}*2 }, } ... $readlength = $varlengths{$var}->(); # compute it

Slightly more work, but worth it I think.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP an inspiration; A true Folk's Guy

Replies are listed 'Best First'.
Re^3: Reading binary files - program structure
by Anonymous Monk on May 25, 2010 at 16:47 UTC
    Interesting, I didn't even know you could do that! Presumably the advantage is speed? Being a compile-time thing rather than a run-time eval?

    If/when I finally make progress on this I'll compare the approaches.

      Presumably the advantage is speed? Being a compile-time thing rather than a run-time eval?

      That's a beneficial side-effect of avoiding string eval. But mostly just a healthy aversion to using it, if it is easier to avoid it.

      I don't subscribe to the evil-eval notion--if I need to evaluate a runtime mathematical expression, I will. Far easier to use Perl's expression parser than write my own, or discover the limitations of someone else's--but for the usage outlined, everything is known at compile-time, so no need to invoke the compiler again (multiple times) at runtime.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.