Good afternoon,
Can you help check my problem with this?
$ cat t1.pl
use strict;
package Myclass;
sub new {
my $self = shift;
bless {},$self;
}
sub run {
my $self = shift;
my $block = shift;
&{$block};
}
1;
package main;
my $obj = Myclass->new;
$obj->run( { "hello world"} );
$ perl t1.pl
Not a CODE reference at t1.pl line 13.
It seems I can't pass a code block to the caller. Where am I doing wrong?
Sorry I have the background of other language, such as in scala I always do:
scala> def strTrans(s:String)(f:String=>String) = f(s)
strTrans: (s: String)(f: String => String)String
scala> strTrans("katorena"){s=>s.reverse}
res0: String = anerotak
scala> strTrans("katorena"){s=>s.take(4)}
res1: String = kato
In above code {s=>s.reverse} and {s=>s.take} are the anonymous func (or
code block) I passed to the caller.
Thank you in advance.
Yamada
Can you help check my problem with this?
$ cat t1.pl
use strict;
package Myclass;
sub new {
my $self = shift;
bless {},$self;
}
sub run {
my $self = shift;
my $block = shift;
&{$block};
}
1;
package main;
my $obj = Myclass->new;
$obj->run( { "hello world"} );
$ perl t1.pl
Not a CODE reference at t1.pl line 13.
It seems I can't pass a code block to the caller. Where am I doing wrong?
Sorry I have the background of other language, such as in scala I always do:
scala> def strTrans(s:String)(f:String=>String) = f(s)
strTrans: (s: String)(f: String => String)String
scala> strTrans("katorena"){s=>s.reverse}
res0: String = anerotak
scala> strTrans("katorena"){s=>s.take(4)}
res1: String = kato
In above code {s=>s.reverse} and {s=>s.take} are the anonymous func (or
code block) I passed to the caller.
Thank you in advance.
Yamada