develooper Front page | perl.beginners | Postings from January 2004

Passing several arguments

Thread Next
From:
Jan Eden
Date:
January 28, 2004 16:35
Subject:
Passing several arguments
Message ID:
r02010000-1032-A6E9A1DA50BB11D8803E000A959B4026@[134.95.169.146]
Hi all,

I have a subroutine which fills into several hashes and arrays (%author_indexlines, %poem_lines, @alphabet_index etc). How can I return those variables and pass them to another subroutine? This does not work, of course

sub read_index {
    blablabla
    return (%author_indexlines, %poem_lines, @alphabet_index);
 }
 
 sub write_index {
    my (%author_indexlines, %poem_lines, @alphabet_index) = shift;
    blablabla
}

    write_index(&read_index);
    
I thought that this might be achieved returning references to the respective arrays and hashes and dereference them after passing, but since the elements have local scope in the read_index sub, I am not sure if this might work:

sub read_index {
    blablabla
    return (\%author_indexlines, \%poem_lines, \@alphabet_index);
}

sub write_index {
    my ($author_ref, $poem_ref, $alphabet_ref) = shift;
    my @author_index = @$author_ref;
    blablabla
}

Any hints appreciated,

Jan
-- 
These are my principles and if you don't like them... well, I have others. - Groucho Marx

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About