Have a look at:
% perldoc perlsub
Esentially you can't return multiple array's (you probably can with
fancy prototyping - but i'm not sure of that) - you usually have to use
references instead.
On Wed, 2003-02-26 at 09:05, Lance Murray wrote:
> Hello:
>
> I know I can return multiple scalar values from a subroutine using an array,
> but how do I return multiple arrays, hashes, etc from a subroutine? For
> example, the following snippet...
>
> my @ip_addresses = &getIPAddresses;
> my (@hostfile, @no_dname) = &getHostNames(@ip_addresses);
> print "\nHOSTFILE: ", scalar @hostfile,"\n",@hostfile;
> print "\nNO_DNAME: ", scalar @no_dname,"\n",@no_dname;
>
> Generates this for output...
>
> HOSTFILE: 411
> NO_DNAME: 0
>
> When what I REALLY want returned is this: (valid data)
>
>
> HOSTFILE: 44
> NO_DNAME: 367
>
> The subroutine I'm using looks like this:
>
> sub getHostNames {
> my (@hostfile,@no_dname,$bitbucket,$hostname);
> foreach my $ip_address (@ip_addresses) {
> my @results = `/usr/sbin/nslookup $ip_address 2>&1`;
> chomp @results;
> foreach (@results) {
> # [PARSE OUTPUT HERE]
> }
> }
> @hostfile, @no_dname;
> }
>
>
> Obviously the subroutine assignments are just merging the contents of the last
> subroutine evaluation statement (@hostfile, @no_dname), and is returning the
> merged values to the first variable (@hostfile/411 elements). How can I return
> discrete arrays and hashes from a subroutine?
>
> Grateful for any help!
>
> Lance
>
>
>
> ------------------------------------------------------------------------------
> This message may contain confidential information, and is intended only for the use
> of the individual(s) to whom it is addressed.
>
>
> ==============================================================================
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]