in reply to whats wrong with my sub-routine ??

Can anyone spot anything?
You need to dereference your array references e.g
my @ar = qw/ foo bar baz /; func(\@ar); sub func { my $ar = shift; ## note the dereference via -> print $ar->[0]; } __output__ foo
See. tye's References quick reference for info references and be sure to use strict to catch these sort of errors.
HTH

_________
broquaint

Replies are listed 'Best First'.
Re: Re: whats wrong with my sub-routine ??
by Coplan (Pilgrim) on Apr 23, 2003 at 16:39 UTC
    Isn't that the same as saying:

    my $ar = qw/ foo bar baz /; func(\@ar); sub func { my $ar = @_; }

    I ask, 'cause that's what he did.

    --Coplan

      Some misunderstandings:

      my $ar = qw/ foo bar baz /;

      In the line above, you're assigning a list in scalar context. You're going to get the last element of that list (baz) assigned to $ar.

      func(\@ar);

      That will throw a warning under strict because you declared a scalar ($ar), not an array (@ar).

      my $ar = @_;

      Now you're accessing an array in scalar context. This will result in $ar being set the the number of elements in @_. Here's a quick demonstration:

      $ perl -e 'sub aa {my $a = @_;print $a}; aa(qw(foo bar baz))' 3

      I realie those seem tricky and frankly, it's often a matter of memorizing how those things behave.

      Cheers,
      Ovid

      New address of my CGI Course.
      Silence is Evil (feel free to copy and distribute widely - note copyright text)

        Uhhh ... doesn't my $ar = @_; put the number of things, not the first thing, into $ar?

        ------
        We are the carpenters and bricklayers of the Information Age.

        Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

        Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.