Well, as pointed out, if you use
parse (@_),
you should see three lines, 2 from the initial call to
parse, and one from the recursive call. If you
examine carefully, you'll notice that the first
Number: 0 comes from the recursive call, and
the last
Number: 0 is from the initial call,
in the second iteration of the
while.
So, what about doing this with &parse you may ask.
Well, if you call from sub1, &sub2, then
sub1 and sub2 will actually share
@_! Look for instance at:
#!/usr/bin/perl
use strict;
use warnings;
sub foo {
print "Foo: [@_]\n";
shift;
}
sub bar {
print "Bar: [@_]\n";
&foo;
print "Bar: [@_]\n";
}
bar 1, 2
__END__
Bar: [1 2]
Foo: [1 2]
Bar: [2]
Shifting off an element of @_ in foo() is noticeable in
bar().
Leaves us the question, why three lines in
perl -d:DProf test.pl when the function is called
as &parse? For that, I do not know the answer.
I can just guess that DProf puts each function
in some kind of wrapper, causing the arguments to get
duplicated.
Abigail
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.