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 | |
by Anonymous Monk on Oct 01, 2014 at 09:38 UTC |