Perlish means taking advantage of perl control structures, data types, and abstractions. It means familiar to someone whose sole language is perl. That some of these perlish constructs look identical to constructs from other languages is not a problem. In fact, I'm sure that most of these constructs were stolen from those other languages anyway.
Abstractions such as using:
instead of:@hash{@a} = @b;
are not only much clearer and cleaner, they probably run faster, too. Perl can pre-allocate a full hash of the right size, meaning only a single allocation. It can really get in there, optimising speed and space, which the C-style code cannot do. In C-land, one would have to do all those optimisations by hand: you'd need an array object which kept track of the length (because counting the array to find the length takes too long for large arrays); you'd need a hash object which could be told to pre-allocate a certain amount of space; you'd need to also remember each time you go populate the hash to pre-allocate the amount of space you need to keep re-allocations to a minimum.for (my $i = 0; $i <= $#a; ++$i) { $hash{$a[$i]} = $b[$i]; }
In perl, all that extra overhead is handled for you. If you follow the perl idiom.
In reply to Perl idioms (was Re^2: Combining two lists into a hash)
by Tanktalus
in thread Combining two lists into a hash
by fthiess
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |