Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

To call a sub from another sub

by tamaguchi (Pilgrim)
on Feb 02, 2006 at 11:21 UTC ( [id://527304]=perlquestion: print w/replies, xml ) Need Help??

tamaguchi has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: To call a sub from another sub
by davorg (Chancellor) on Feb 02, 2006 at 11:29 UTC

    Er... yes. It works exactly how you'd expect it to. Or, at least, how I'd expect it to. What did you try? What happened when you tried it?

    sub a_subroutine { print "this is a subroutine\n"; } sub another_subroutine { print "this is another subroutine\n"; a_subroutine(); } another_subroutine();
    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Re: To call a sub from another sub
by tirwhan (Abbot) on Feb 02, 2006 at 11:27 UTC

    Did you try it out? It just works(tm).

    perl -e 'sub one{print "one\n"};sub two{one()};two()'

    Dogma is stupid.
Re: To call a sub from another sub
by bart (Canon) on Feb 02, 2006 at 11:29 UTC
    The same way as you'd call it from the top level. Have you tried it?

    I think you should spend some time in the first chapters of some Perl books for beginners, like Learning Perl by our own merlyn, or Beginning Perl by Simon Cozens. If you look closely at the latter page, you can find a link to a free online version.

Re: To call a sub from another sub
by TedPride (Priest) on Feb 02, 2006 at 11:31 UTC
    He probably wants to know how to pass one sub as an argument to another:
    use strict; use warnings; bongo(\&bingo); sub bingo { print "bingo"; } sub bongo { my $p = $_[0]; $p->(); }
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: To call a sub from another sub
by TedPride (Priest) on Feb 02, 2006 at 12:04 UTC
    use strict; use warnings; whatever(); sub whatever { my $value = 5; $value = increment($value); print $value; } sub increment { return $_[0] + 1; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://527304]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (7)
As of 2024-03-19 03:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found