in reply to RE: RE: Hash Push
in thread Hash Push

Hey, I like that... Could I hide the whole thing too?
Maybe write:
sub GetData { my %data; sub Recursive { # do stuff # push onto %data # call Recursive if appropriate } Recursive(); return \%data; } my %data = %{GetData()}; # Can this be cleaner?

Replies are listed 'Best First'.
RE: RE: RE: RE: Hash Push
by merlyn (Sage) on Aug 16, 2000 at 22:29 UTC
    Well, I'm not sure why you'd want to do that. For one, you now have nested subroutines with the ol' "Value won't stay shared" in the middle to boot. If you control the call to your subroutine, you can require they pass it by reference as the first parameter. If you don't, wrapper it up in a helper routine:
    sub routine_that_they_call { my @args = @_; my %data_to_be_filled; recursive_subroutine(\%data_to_be_filled, @args); return \%data_to_be_filled; }
    Now you don't have to define a nested subroutine.

    -- Randal L. Schwartz, Perl hacker