Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: reference to a sub

by sk (Curate)
on Sep 11, 2005 at 07:34 UTC ( [id://491027]=note: print w/replies, xml ) Need Help??


in reply to reference to a sub

I think the question of when references to subs are used and anonymous subs are used is too broad.

Here is a simple example of anonymous sub -

my @sorted = sort { $a <=> $b } @unsorted;

In the above block we passed an anonymous sub to sort. It is just easy (convenient) to write numeric sort that way than to define a sub that returns  $a <=> $b

An example of sub ref is signal handling

$SIG{INT} = \&catch_int;
These examples are very simple. Others might contribute better examplese. Another thing i can think of is closures where you return a reference to a sub from inside another sub.

-SK

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-18 19:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found