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


In reply to 'use strict', debugger, Data::Dumper by TomDLux
in thread sub returning undef by Scarborough

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.