in reply to How to get two array in subroutine

If you want to walk on the wild side, you can use the (very) old-fashioned typeglob arguments for passing something like a reference that is yet not (quite) a reference... technically... I guess... See Typeglobs and Filehandles in perldata.

>perl -wMstrict -le "use Data::Dumper; ;; our @a = (1, 2, 3, 4); our @b = (9, 8, 7, 6); f(*a, *b); ;; sub f { local (*c, *d) = @_; print Dumper \*c; print Dumper \*d; print @::c; print @::d; } " $VAR1 = \*::a; $VAR1 = \*::b; 1234 9876

(OTOH, the prototype answer given by CountZero is probably what your interviewer/teacher is looking for.)

Replies are listed 'Best First'.
Re^2: How to get two array in subroutine
by CountZero (Bishop) on Feb 10, 2011 at 06:30 UTC
    I shudder to think about a teacher or interviewer who wishes to check if the student or interviewee knows about such *forbidden* knowledge as prototypes. Personally I will give better marks to someone who says it needs to be done with references than to someone who immediately thinks about prototypes and still calls subroutines the "ampersand" way, thus utterly defeating the use of prototypes. Those are not the people you want to tinker with the control program of your nuclear reactor.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James