[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]

the \& prototype (?)



While writing an article on typeglobs and prototypes, I decided to see
what the (\&) prototype does:

  sub bar (\&) { 1 }
  sub foo { return "foo!" }

  bar \&foo;
  bar &foo;
  bar foo;
  bar sub foo { return "foo!" }
  bar sub { return "foo!" }
  bar { return "foo!" }

NONE of the calls to bar() worked.  Each gave me an error message:

  bar \&foo;
    Type of arg 1 to main::bar must be sub (not reference constructor)

  bar &foo;
    Type of arg 1 to main::bar must be sub (not subroutine entry)

  bar foo;
    Type of arg 1 to main::bar must be sub (not subroutine entry)

  bar sub foo { return "foo!" };
    syntax error at - line 4, near "bar sub foo "

  bar sub { return "foo!" };
    Type of arg 1 to main::bar must be sub (not reference constructor)

  bar { return "foo!" };
    Type of arg 1 to main::bar must be sub (not scalar ref constructor)

Now, I know the \& prototype is not documented anywhere, but perl seems to
think it exists.  So what is a "sub"? :)

-- 

  MIDN 4/C PINYAN, USNR, NROTCURPI     http://www.pobox.com/~japhy/
  jeff pinyan: japhy@pobox.com     perl stuff: japhy+perl@pobox.com
  CPAN ID: PINYAN  http://www.perl.com/CPAN/authors/id/P/PI/PINYAN/
  PerlMonth - An Online Perl Magazine     http://www.perlmonth.com/


[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]