In production code I’m likely to call that subroutine something more like _n.

3
NotNumber: rhubarb

Subroutine Call Speed

This is why I care about perl subroutine call speed – I have so many little routines stating exactly what I expect from my code. And it seems like it is quick enough.

It would be nice though to have something like emacs’ defsubst. Say a new keyword like inline_sub { ... }. So I can invent the syntax I want, secure in the knowledge that, code bloating aside, I’m not paying for it.

Share this:

Like this:

Related

6 Responses

Autovivification – is a very comfortable thing, workarounds around it says that you doesn’t understand Perl-way programming good and you may read some books like “Intermediate Perl” and “High order Perl”, to understand that way and your programs will be much better without workarounds.

Second example (about numbers) i never used in my life in any language =). I can not even imagine where this might come in handy, so you worry about this.

Your problems with Perl programs is in not so good understanding of the language. Try to understand it principles or write your programs in python if deems more appropriate.

It is ridiculous to suggest that wanting to avoid autovivification means that Jared isn’t a good Perl programmer. (It’s also irrelevant, since this post does not actually reference autovivification, which is when an undefined value is silently upgraded to an array or hash reference.)

Perl has a lot of features to make writing quick programs easy. Those same features are often a pain when you have to look through 50k lines of code and figure out why your data is silently being converted from one thing to another somewhere in the middle. In that context, finding a way to avoid accidental nonexistent hash key lookups is perfectly reasonable.

I don’t know about you, but I tend to access hashes more than I add keys to them. One way to get this typo protection and avoid paying the cost on every access is to use Hash::Util’s (http://perldoc.perl.org/Hash/Util.html) lock_keys_plus: