Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing lists to functions (and reading again) 2

Status
Not open for further replies.

carlosAlberto

IS-IT--Management
Oct 9, 2001
109
GB
Hi everybody,

I'm having a few problems passing a list (along with other variables) to a sub routine, then reading this list (@replyData) within the sub routine.

Call to sub routine:

buildStatusReport($ipAddress, $miboid, @replyData);



In subroutine:

my $ipAddress = $_[0];
my $miboid = $_[1];
# my @replyData =

How do i define @replyData in my sub routine which contains only the items from the replyData list ????


Thanks,

Carlos.
 
The easiest way is to pass a reference to the list by using '\@' like:

Code:
my $scalar1 = 1;
my $scalar2 = 2;
my @array = (3, 4, 5);

foo($scalar1, $scalar2, \@array);

sub foo {
  my( $x, $y, $ref ) = @_;
  print "x: $x\n";
  print "y: $y\n";
  foreach( @$ref ) {
    print "$_\n";
  }
}
Hope this helps. Cheers, Neil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top