in reply to how to let sub return hash of 2 sub?
my $x = sub { print shift };
To call such a subroutine, use the ->() dereference:
$x->('Hello world!');
It's a bit unclear what exactly you need. The following sub returns a hash of two subs:
#! /usr/bin/perl use warnings; use strict; sub two_subs { return { first => sub { return 'First: ' . shift }, second => sub { return 'Second: ' . shift }, } } print two_subs()->{first}->('A'), ' ', two_subs()->{second}->('B'), "\ +n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: how to let sub return hash of 2 sub?
by Anonymous Monk on May 27, 2015 at 15:20 UTC |