« Music on the Brain | Main | Minimal Perl Review »

Evil Perl Function Calling

Evil Perl, not for use anywhere near production code. Means to bypass prototype (and strict) restrictions in Perl.

#!/usr/bin/perl -wl use strict; sub noproto { print "Got: @_"; } sub proto($$) { print "Got: @_"; } # fails, as expected #proto(42); { local @_ = 42; &proto; } # these work &proto(42); &proto(); # not happy #&proto 42; # this bypasses 'strict' and prototypes, but adds # 'main' to @_ my $be_evil = 'proto'; main->$be_evil(42); # there we go... __PACKAGE__->can($be_evil)->(42);

Technorati Tags: