On Thu, 30 Sep 2004 20:19:11 +0100, Graeme McLaren
<[EMAIL PROTECTED]> wrote:
> Hi all, I'm having a look in to object oriented perl.  Can anyone tell me
> what the difference between @_ and shift is?  As far as I know there is no

Straight from "the Llama" :
@array = qw /dino fred barney/;
$a = $shift @array; # $a gets "dino", @array reduced to ("fred" , "barney");

> difference except "shift" removes the parameter from the @_ array so if you
> were to "shift" all parameters passed to a function nothing would be
> containted in @_   is this correct?

@_ variable is local to the subroutine. It stores argument to a
subroutine. If u keep on doing "shift" inside a subroutine then @_
will be empty & will become uninitialized again.
  sub test {
              #$a = shift ;
      my $a = shift @_ ;
      print $a;
      my $b = shift @_;
      print $b;
      }
&test(1);
->perl -w test.pl
->Use of uninitialized value in print at test.pl line 9.
1

But this doesn't in anyway affect the @_ variable outside the
subroutine if there happens to be any.

> I'm asking because I'm a little confused about using it.  Why can't I do
> this:
>
> #######################################
> sub nickname {
>        my $self = shift;
>        return $self->{NICK};
> }
> #######################################
>
[snip]

"$self" looks alot like "this" in Java.. no? :)

-- 
Cheers,
SanoBabu

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


Reply via email to