2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

canの使い方

Posted at

methodなかったらundef返すとかそういう使い方

cancam.pl
#!/usr/bin/env perl

use strict;
use warnings;
use Data::Dumper;

use v5.12;

{

    package Powawa;

    sub powapowa {
        # nothing code; 
    }

  }

for my $hoge (qw/powapowa popo popopo/) {

    my $code = Powawa->can("$hoge");

    print Dumper $code;

    if ( defined($code) ) {

        print "$hogeメソッドを見つけたよ。\n\n";

    }
    else {

        print "$hogeメソッドは見つからなかったよ。\n\n";

    }

}

__DATA__

$VAR1 = sub { "DUMMY" };
powapowaメソッドを見つけたよ。

$VAR1 = undef;
popoメソッドは見つからなかったよ。

$VAR1 = undef;
popopoメソッドは見つからなかったよ。
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?