develooper Front page | perl.perl5.porters | Postings from March 2008

builtin() versus builtin( () )

Thread Next
From:
Elizabeth Mattijsen
Date:
March 11, 2008 16:02
Subject:
builtin() versus builtin( () )
Message ID:
p06240800c3fc8592de18@[192.168.0.72]
Something I ran into while toying with Merijn's idea of freezing time 
(as presented on the last NL Perl Mongers meeting).


$ perl -le 'print scalar localtime( () )'
Thu Jan  1 01:00:00 1970
$ perl -le 'print scalar gmtime( () )'
Thu Jan  1 00:00:00 1970

Note the extra () specified.

Similarly:

$ perl -le '$_ = []; print ref( )'
ARRAY
$ perl -le '$_ = []; print ref( () )'


If this is intended behaviour, I wonder how you can destinguish 
between no parameters specified, and an empty list specification from 
within a called subroutine?

$ perl -wle 'sub a { print scalar @_ } a';
0
$ perl -wle 'sub a { print scalar @_ } a()';
0
$ perl -wle 'sub a { print scalar @_ } a( () )';
0


Checking @_ clearly doesn't help.  Checking caller() neither:

$ perl -wle 'sub a { print  +(caller(0))[4] } &a';
0
$ perl -wle 'sub a { print  +(caller(0))[4] } a';
1
$ perl -wle 'sub a { print  +(caller(0))[4] } a()';
1
$ perl -wle 'sub a { print  +(caller(0))[4] } a( () )';
1


The reason I'm asking, is that I want to be able to completely mimic 
the behaviour of builtins when they're wrapped by custom code: it 
would seem to me that that is basically impossible at the moment.  Or 
am I missing something?



Liz

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About