in reply to using sub routines and solving an issue i have with passing variables

Could what you are asking be accomplished by passing in your data structure into each of the subroutines as an additional parameter? E.g.

sub parse1 { my ($filehandle,$data) = @_; # read from $filehandle and add to $data } sub parse2 { my ($filehandle,$data) = @_; # read from $filehandle and add to $data } # etc.

Or perhaps better, each subroutine could return the piece of data it parsed from the file?

my %data; $data{piece1} = parse1($fh); $data{piece2} = parse2($fh); sub parse1 { my ($filehandle) = @_; # read from $filehandle return $data; } sub parse2 { my ($filehandle) = @_; # read from $filehandle return $data; }

But I think I may be misunderstanding the question, in which case it would help if you could explain some more and provide a small, working, self-contained example that demonstrates the question, along with some sample input and the expected output. How do I post a question effectively?

Replies are listed 'Best First'.
Re^2: using sub routines and solving an issue i have with passing variables
by james28909 (Deacon) on Oct 01, 2014 at 01:41 UTC
    well there are still afew things in which i am not to sure about. one of which is return function. does that return the data outside of the sub? i have had alot of spare time recently and i wanna learn all i can, i dont want to feel like an idiot for asking, but i read thru some of the perldocs and dont understand alot of the talk about it as i am better with written examples and a little explanation. let me better prepare my question. or should i say questionS <.<