On 6/2/07, Alma <[EMAIL PROTECTED]> wrote:
Hi,

I need to pass id as parameters to a subroutine

testsub(35);

sub testsub($)
   {
   my $self = shift;
   my $id = @_;
   print "$id";
}

Its printing 3 . am i going wrong in prototype .

First off, don't use prototypes until you know exactly what they do.
They don't do what you think the do*.  Don't worry about this though
since they don't do what most people would expect them to (it is all
getting fixed in Perl 6).

Second off, it looks like your subroutine is written in Object
Oriented Style, but you are calling it in Procedural Style.  If this
is not supposed to be an OO method than you should lose the "my $self
= shift;" part.  Also, going back to the first issue, prototypes are
ignored for OO methods.

Third off, "my $id = @_;" puts the array @_ in scalar context.  That
means it returns the number of elements in side of it, not the
elements themselves.  If you are indeed printing 3, then this is the
likely culprit.  Context is incredibly important in Perl and you must
always be careful that you are calling functions and accessing .  You
should say

my ($id) = @_;

* http://groups.google.com/group/comp.lang.perl.modules/msg/84484de5eb01085b

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to