On Jul 12, Vincent said:

>I'm reading the chapter on Subroutines in the camel book and have a question
>about the prototypes described on page 226.
>At first my understanding was, there should be a $ or @ for each parameter
>expected.  Or a \@ or \$ for each reference expected.  But one of the
>examples reads:

A \@ means that the function is expecting an array, and it will convert it
into a reference to an array.  A \$ means that the function is expected an
EXPLICIT scalar variable, and will turn it into a reference.  A $ means
that the argument will be evaluated in scalar context.

  sub FOO ($) { print $_[0] }

  @a = (10,20,30);
  $b = 30;

  FOO(@a);     # 3 -> scalar(@a) == 3
  FOO($b);     # 30
  FOO(@a,$b);  # compile-time error -- too many args  

>Also there's some prototypes with a semicolon in them

The semicolon indicates that the following arguments are optional.

Prototypes are documented in 'perlsub', and I have an article that
discusses them:

  http://www.pobox.com/~japhy/articles/pm/2000-03.html
  "Typeglobs and Prototypes"

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
Are you a Monk?  http://www.perlmonks.com/     http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc.     http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter.         Brother #734
**      Manning Publications, Co, is publishing my Perl Regex book      **

Reply via email to