As an lvalue “keys” allows you to increase the number of hash buckets allocated for the given hash. This can gain you a measure of efficiency if you know the hash is going to get big.
Taken from
perldoc -f keys
. Awesome!
Archives for posts tagged ‘perl’
How to pre-allocate memory for a large hash in Perl
Tuesday, 15 April 2008
Transforming Java to Perl
Sunday, 13 April 2008
What a bold statement! Do these something less than 100 lines of Perl really transform each and any Java program into its Perl equivalent? No, they don’t. But what they do is just the way I use automation: automate what you can automate easily and leave some work unfinished, so it doesn’t get too boring [...]
Perl myths
Tuesday, 18 March 2008
If you are a Perl professional and you feel that the way you and your co-workers use Perl is not entirely flawless, Tim Bunce’s slides about Perl myths are a must-read for you.
I stumbled over it, read the first few pages and greedily slurped it to the end. These slides contain some nice-to-know Perl details [...]
Learning Python: Chapter 19
Monday, 3 March 2008
from-statements let you expose your code to the amout of namespace pollution you like:
from some_module import some_function (like use CGI qw(header); in Perl)
Symbol tables of modules are accessed through the dictionary named __dict__.
Learning Python: Chapter 16
Friday, 22 February 2008
Perl
Python
my $x = 10;
sub foo
{
$x = 20;
}
x = 10
def foo():
global x
x = 20
Declaring a variable in a function as global is only necessary for reassignments, not for mere read-access.
def foo(x, y, z): pass
foo(10, 20, 30)
does the same as
[...]
Template Toolkit - Now With Added Python Goodness!
Sunday, 10 February 2008
I had some idiosyncratic learning experiences lately. I read something about two things I want to learn about and suddenly, without explicitly searching for it, stumble upon something that deals with both of them. This happened again this morning. The two things that I was already learning were Python and the Template Toolkit.
As a Python [...]
Learning Python: Chapter 5
Friday, 8 February 2008
After four chapters of introductory details I finally arrived at the in-depth explanation of Python that I actually looked forward to. Here’s all I found noteworthy from a Perl programmer’s point of view.
There are functions for explicit type conversion between individual numeric types: int(3.1415), float(3), long(4).
After saying
[...]
Debug::Phases
Thursday, 7 February 2008
Debug: hases - Announce BEGIN and INIT phases to help locate problems:
This tiny module does nothing but announce the start of the BEGIN and INIT phases, recording how long the compilation (BEGIN phase) took. It’s handy for tracking down whether particular problems are compile-time or run-time, and also for evaluating the time-cost for using [...]
Effective Perl Programming: Item 11: Consider different ways of reading from a stream
Wednesday, 30 January 2008
Ever wondered if there was a better way of reading a file into a single scalar than
$the_file = join ”, <FH>;
There is!
{
local $/;
$the_file = <FH>;
}
Not only does this save you the join, the actual reading from the file is done much faster that way.
for (<FH>) { … }
generally does the same as
while (<FH>) [...]
Effective Perl Programming: Item 10: Avoid excessive punctuation
Wednesday, 30 January 2008
The traditional & syntax has its uses—it’s the only way to call a subroutine whose name is a keyword, for example, &for
Using keywords as subroutine identifiers? What could this possibly be useful for, except confusing co-workers? Due to the fact that the book is about "Writing better programs", they should have indicated this as being [...]
A Short History of Nearly Everything
Seven Languages in Seven Weeks
I Am a Strange Loop