> Is it possible for a subroutine to return both a scalar (an integer, 
specifically) *and* a reference to an array of arrays? 
sub add_row { 
my ($counter, @ary) = @_; 

   # do stuff to @ary... 

   # add scalar to @ary: 
   push( @ary, ++$counter ); 

   return( [EMAIL PROTECTED] ); 
} 

# sample call: 
@added_stuff = @{ add_row( $out_count, @added_stuff) }; 
$out_count = pop( @added_stuff ); 

yeah, you can return a list in list context. 
sub add_row { 
my ($counter, @ary) = @_; 
   # do stuff to @ary... 
   ++$counter; 

   return( [EMAIL PROTECTED], $counter); 
} 

my ($add_stuff_ref, $out_count) = add_row($out_count, @added_stuff);

A little counter-intuitive, the call and return orderings here. So this 
does smack of some need for refactoring here.   You could pass these by 
ref, not value, so that would avoid some of this sort of back and forth.
sub add_row { 
my ($counter_ref, $ary_ref) = @_; 
   # do stuff to @{ $ary_ref }... 
   ++$counter_ref; 
     return;
}

add_row( \$out_count, [EMAIL PROTECTED]);

That's ugly action at a distance so use the return value as some kind of 
success marker:
sub add_row { 
   my ($ary_ref) = @_; 
      my $do_stuff_worked = 0;
   # do stuff to @{ $ary_ref }... 
   return $do_stuff_worked; 
}

$out_count++ if add_row([EMAIL PROTECTED]);

unless you need $out_count in the "do stuff" code.  But it's a start.

a

Andy Bach
Systems Mangler
Internet: [EMAIL PROTECTED]
VOICE: (608) 261-5738  FAX 264-5932

"Men are always wicked at bottom unless they are made good by some 
compulsion." 
Niccolo Macchiavelli
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to