in reply to setting values inside subroutine

can i make @r an optional argument (reference) and call sample { my ($t, $r_ref) = @_; my @r; @r //= @{$r_ref} .. } # from my own sub?

Replies are listed 'Best First'.
Re^2: setting values inside subroutine
by Anonymous Monk on Sep 18, 2015 at 23:03 UTC
    yes, just try it ... no need to expand into @r its easy to  $r_ref->[0]

      I called sample from my own sub like this, with the intention of accessing 0th element of @r defined in sample.Its not working. Can you let me know, what is missing here

      sub temp { sample(($t,$r_ref) = @_ ; $r_ref->[0]); }
        I dont know what you're trying to do , maybe this but its hard to tell
        sub temp { my( $t, $r_ref ) = @_; sample( $r_ref->[0] ); }