Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password

Programming > Perl Beginners > RE: help in whi...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 10748 of 11948
Post > Topic >>

RE: help in while loop

by t.baetzler@[EMAIL PROTECTED] (T Baetzler) Mar 17, 2008 at 04:30 PM

Irfan.Sayed@[EMAIL PROTECTED]
 asked:
> I have certain doubts.=20
>=20
> What's the meaning of " if
> mysubroutine was defined with prototypes and you were trying=20
> to disable that" sentence.=20
>=20
> Could you please elaborate that what's the meaning of this???

When declaring a subroutine, you can optionally also declare
a prototype for it - i.e. the number and type of arguments.

This allows for a limited sort of compile time parameter
checking aswell as parameter type coercion.

For example:

#!/usr/bin/perl -w

use strict;

sub prototyped ($) {
  print "prototyped args: ", join(', ', @[EMAIL PROTECTED]
 ), "\n";
}

sub unprototyped {
  print "unprototyped args: ", join(', ', @[EMAIL PROTECTED]
 ), "\n";
}

my @[EMAIL PROTECTED]
 =3D qw( foo baz bar );

prototyped @[EMAIL PROTECTED]
 @[EMAIL PROTECTED]
 @[EMAIL PROTECTED]
 args: 3
unprototyped args: foo, baz, bar
prototyped args: foo, baz, bar

The first sub is declared with a prototype to expect a scalar value as =
the first argument. This declaration forces the argument @[EMAIL PROTECTED]
 into =
scalar context, so that it evaluates to the number of elements in the =
array, i.e. 3.

Without the prototype, the array is passed as an array to the =
subroutine.

If you use the old-style subroutine calling syntax with a prepended &, =
any prototypes for the function are disabled.

Please see the perlsub manpage ("perldoc perlsub") for the
gory details on prototypes and subroutine calling syntax.

HTH,
Thomas
 



 1 Posts in Topic:
RE: help in while loop
t.baetzler@[EMAIL PROTECT  2008-03-17 16:30:46 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Oct 7 16:24:58 CDT 2008.