Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: optimization help

by naikonta (Curate)
on Oct 16, 2007 at 01:01 UTC ( #645083=note: print w/replies, xml ) Need Help??

in reply to optimization help

if (/^sub /) { return eval->( evalTree($intree->{left},$param), evalTree($intree->{right},$param) );
This is tricky, but its trickiness doesn't help in any means. I needed to lookup perldoc -f eval again to make myself sure that eval is one of them that takes $_. I still wonder, though, experienced monk like samtregar got bitten too (sorry, Sam) :-) I still thank him for giving me a little hint (thank you, Sam).

This reminds me of a friend that made use of eval in a "unique" way, the first time I saw that time.

#!/usr/bin/perl # no -w # no strict eval { ... the rest of the program... }; die $@ if $@;
There was nothing wrong with this program, syntatically, and it worked. I coudn't explain then, but I knew this was not right so I rejected his code and told him to code in the usual manner. Now I can say that unnecessary double evaluation is evil.

These two examples prove a) TMTOWTDI principle, b) not all W's are equal.

Otherwise your tomatoes, rotten cabbage, and half eaten apples are appreciated
No, I won't do that, especially when I know that this is not originally your own code. Even if it was, there was still no reason to do so. You asked in the proper manner. ikegami has said what was wrong and the correction as well.

Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!

Replies are listed 'Best First'.
Re^2: optimization help
by chromatic (Archbishop) on Oct 16, 2007 at 05:43 UTC

    eval BLOCK and eval STRING are completely different. It's unfortunate that they share the same name. There's (almost) nothing wrong with the code your friend wrote.

      Agreed. It was an eval BLOCK so it happened at compiled-time. I just didn't (and still don't) see any advantage other than aggregating fatal errors checking, such as
      my $dbh = get_db(); # with RaiseError => 1 eval { my $some_sql = get_some_sql_code(); $dbh->do($some_sql); my $another_sql = get_another_sql_code(); $dbh->do($another_sql); ... more query execution }; die $@ if $@;

      Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://645083]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2019-07-22 10:31 GMT
Find Nodes?
    Voting Booth?
    If you were the first to set foot on the Moon, what would be your epigram?

    Results (14 votes). Check out past polls.