Here's one way, but if you create @f like you want to, then you will end
up working with a copy of your array instead of the original array
passed.  That may or may not be what you want to do.  

If you want to alter the contents of the original array, you will have
to use $f and dereference it.  When working with the reference, if you
need an array (when using sort() for example), use @{$f} or @$f.  When
you want to access an element of the array, use $f->[element].

NOTE:  Always use strict and warnings.  It's much better to start now
than to have to change your habits later.  It's like learning to type;
at first it makes things slower, but in the end it will help a lot.


##################################

use strict;
use warnings;

my @a = (1,2,3,4);
my $b = 10;
my $c = 5;

d($b,[EMAIL PROTECTED],$c);

sub d {
   my $e = shift;
   my @f = @{shift()};
   my $g = shift;

   print $f[2], "\n";
}

###################################




-----Original Message-----
From: Bryan R Harris [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, February 22, 2006 12:39 PM
To: Beginners Perl
Subject: simple references question



I'm trying to pass an array to a subroutine.  I'd like the subroutine to
create "@f" from the "[EMAIL PROTECTED]" that I send it, but I can't seem to 
figure
out
the syntax.  Is there a way to replace my "???f???" with something to
make
it work?

**************************************

@a = (1,2,3,4);
$b = 10;
$c = 5;

d($b,[EMAIL PROTECTED],$c);

sub d {
   ($e,  ???f???  ,$g) = @_;
   print $f[2], "\n";
}

**************************************


TIA.

- Bryan



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




--
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