Jan Eden wrote:
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, [EMAIL PROTECTED]);
}

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

Any hints appreciated,


"Not sure if it might work"... did you try? Trial and error is the best way to learn....


perldoc perlreftut
perldoc perlref
perldoc perldsc
perldoc perllol

Until you have a strong grasp of references make heavy use of Data::Dumper it is your friend and will help you wrangle more complex structures.

May I also suggest to improve your understanding of scoping issues:

http://perl.plover.com/FAQs/Namespaces.html

http://danconia.org

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to