[Israel.pm] Mode interesting Code

Shmuel Fomberg semuelf at 012.net.il
Tue Oct 24 15:07:45 PDT 2006

Hello There.

The Code: (out of the memory, so forgive me)

Sub someFunc {
   My $self = shift;
   My @args = @_;
   My @inVars = ($args[0], $args[1],....);
   My @outVars = ($args[7]);
   $ret = someCall(@inVars);
   .... extracting from $ret an array, lets call it @a
   foreach (@outVars) {
     $_ = shift @a;

What is going on here? Someone ported code from CORBA. 
If you're familiar with CORBA, every function call there have "in" and
"out" parameters.
And our brilliant programmer heard that foreach make $_ an alias to the
elements inside the array, so he used it to change the given parameters.
Simply brilliant. And this exists in a working code.

Ah well. Maybe I'll ask my boss to give me a free hand for a week, and
will rewrite this library.

Have fun,

More information about the Perl mailing list