27 Sep 2002 xach   » (Master)

I've been trying to use prototypes to make new utility functions in perl. The "perlsub" documentation says this:

Perl supports a very limited kind of compile-time argument
checking using function prototyping.  If you declare

sub mypush (\@@)

then "mypush()" takes arguments exactly like "push()" does.

But that doesn't seem to be my experience. I wrote a function called linsert. The definition is:

sub linsert (\@$@) {
    my ($aref, $index, @elts) = @_;
    splice(@{$aref}, $index, 0, @elts);

Then I tried to write mypush using linsert:

sub mypush (\@@) {
    my ($aref, @elts) = @_;
    linsert(@{$aref}, $#{$aref}, @elts);

It doesn't work; the original array is not altered. But if I use the built-in push instead of linsert, it magically works. It seems that this makes it impossible to build a pyramid of utility functions, as the base functions don't seem work as expected unless they're built in.

I also found out that $a and $b are special when "strict" is concerned. I had good luck making a "foreachpair" utility function, but I got tripped up when making "foreachtriplet". Ugh.

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!