Yes because your not shifting any values just a memory address.
Here this might help
---------------
When you do your sub call
mysub ($myvar, $myvar2)
An array is created in your subroutine that holds both those values. It
is called @_.

So in the sub
@_ holds ($myvar, $myvar2),
So $_[0] = $myvar.

All shift does is empty the @_ array

So my $newvar = shift 
Would give $newvar the value of $_[0] and remove it from the array 
So now the array @_ only holds $myvar2 and it is now $_[0]. The first
varirable was shifted out of the array.

Now as to your question. Your not passing an array just the memory
location of it.
Which is something along the lines of...
ARRAY(0x185f3fc)

That is it. Just that string is all that is in $value of your sub
routine.
Just that string which happens to be an address to the "REAL" array.

You can test this. Simply add a print statement to your routine that
prints $value and you will see what I mean.

When you want to use the values of the array you dereferance it which is
why you are using double $$ or @$ 
Which reads as the string value contained at this mememory address.

So $$value[0] literaly means use the array item 0 contained at the
memory address of $value.

Its confusing. You should read up on refreances. Or if your not ready to
use them pass the whole array by removing the \ in the sub call. This
will send the entire array to your subroutine actually it passes a copy
of the array so that changes made in the sub don't affect the real
array.

You could also leave the array as a global variable and not pass it at
all and just use the array like you would anywhere else.

BUY learning perl by oriely. You can blow through it in an afteroon and
it will clear up a lot of this a lot better then I can explain. 

I am Ccing the list so that others can contribute. Also if others are
having the same questions you are having it will benefit them. I don't
mind you mailing me directly but if its perl related send a copy to the
list for everyones benefit.

I think I just confused my self :)

Paul

-----Original Message-----
From: Antonio Jose [mailto:[EMAIL PROTECTED] 
Sent: Friday, August 22, 2003 11:20 AM
To: [EMAIL PROTECTED]
Subject: About Shift


Hello

Can I use shift if I want to manipulate and to do calculus with the
vector value?. In the case down it's possible becuase I am not going to
do something with it, only print the length. like this (example):

#!/usr/bin/perl
use strict;
use warnings;

sub suavizar {
  my ( $prof, $value ) = ( shift, shift );     # same as ( $_[0], $_[1]
);
  $long = . scalar (@$value) . ;
  print "Length of value = " long "\n";       # @$value
  my $nada = 0;
  for ($i=0; $i <= $long; ++$i) {
      $nada = $value[$i] + $nada;
       }
  print "addition = "$nada[$i]"\n";
(arrary referenced in $value)
}

my $prof = 'some variable';
my @value = ("item1","item2","item3");
suavizar ( $prof, [EMAIL PROTECTED] );
        
Thanks



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to