in reply to sub returning undef

WhenI looked at your code, I wondered that you didn't have parentheses when you call mysub1, but it slipped past me all the same, until I did what you should have done, run the code in the debugger.

&mysub2(mysub1) invokes mysub2 with the text 'mysub1'; so @array is not empy.

If you used

use strict;

as you should, you would have been provided the warning

Bareword "mysub1" not allowed while "strict subs" in use at <file, lin +e number>

Even without that warning, if you're confused that mysub2() is following the wrong path, the obvious thing to do is to find out what @array DOES contain, since it doesn't contain what you expect it to. You could print out what @_ contains at the routine entrty point, in which situation Data::Dumper is your friend.

use Data::Dumper; sub mysub2 { print STDERR Dumper( \@_ ), "\n"; my @array = @_;

will let you see things are not as you thought.

Or you could use your debugger. I prefer debugging from emacs (M-x perldb) but not everyone wants to spend the time to learn to use emacs. So use perl -d myscript, then type a letter 's' to 'single-step' into the mysub1() routine. "WOW! What are we doing in mysub2()?". Seeing the code elsewhere than you expected does a lot to guide your debugging ... :-)

--
TTTATCGGTCGTTATATAGATGTTTGCA