rsennat has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,
How do I pass hash and array to a subroutine and process in it.
$status->jobs_terminate(%hoh, @del_ids); sub jobs_terminate { my $self = shift; my (%hoh, @del_ids) = @_; print Dumper \%hoh; foreach my $id (@del_ids) { print $id; } }
This is not returning properly. How do I go abt this?
Thanks
rsennat

Replies are listed 'Best First'.
Re: pass several arguments to a subroutine
by jeffa (Bishop) on Nov 07, 2005 at 16:13 UTC

    Pass references:

    $status->jobs_terminate(\%hoh, \@del_ids); sub jobs_terminate { my $self = shift; my ($hoh, $del_ids) = @_; print Dumper $hoh; foreach my $id (@$del_ids) { print $id; } }

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
Re: pass several arguments to a subroutine
by Roy Johnson (Monsignor) on Nov 07, 2005 at 16:20 UTC
    For more answers to common, useful questions, please browse the Q&A section. In the Subroutines section, you find your question answered.

    Caution: Contents may have been coded under pressure.
Re: pass several arguments to a subroutine
by polettix (Vicar) on Nov 07, 2005 at 16:26 UTC
    perlsub, "Pass by Reference" paragraph:
    If you want to pass more than one array or hash into a function--or return them from it--and have them maintain their integrity, then you're going to have to use an explicit pass-by-reference. Before you do that, you need to understand references as detailed in perlref. This section may not make much sense to you otherwise.
    Definitively something to read!

    Flavio
    perl -ple'$_=reverse' <<<ti.xittelop@oivalf

    Don't fool yourself.
Re: pass several arguments to a subroutine
by svenXY (Deacon) on Nov 07, 2005 at 16:14 UTC
    Hi,
    pass them as references
    $status->jobs_terminate(\%hoh, \@del_ids); sub jobs_terminate { my $self = shift; my ($hoh, $del_ids) = @_; print Dumper $hoh; foreach my $id (@{$del_ids}) { print $id; } }

    Regards,
    svenXY
Re: pass several arguments to a subroutine
by rsennat (Beadle) on Nov 07, 2005 at 16:25 UTC

    Thanks a lot. Immd. I got it.
    $status->jobs_terminate(\%hoh, \@del_ids); sub jobs_terminate { my $self = shift; my ($hoh, $del_ids) = @_; my %h = %$hoh; my @d = @$del_ids; }
    Thanks
    rsennat