1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#!/usr/bin/env perl use strict; use warnings; use 5.010; use Scalar::Util qw(reftype); package Package_a_ref; sub new { return bless [ qw( a b c ) ], shift; } package ARRAY; sub new { return bless { one => 1 }, shift; } package main; sub print_array_ref_AAA { # ref my ( $a_ref ) = @_; die ">no arguments" if not @_; die ">not defined" if not defined $a_ref; die ">not a reference" if not length ref $a_ref; die ">not an ARRAY reference" if ref( $a_ref ) ne 'ARRAY'; say for @$a_ref; } sub print_array_ref_BBB { # reftype my ( $a_ref ) = @_; die ">no arguments" if not @_; die ">not defined" if not defined $a_ref; die ">not a reference" if not defined reftype( $a_ref ); die ">not an ARRAY reference" if reftype( $a_ref ) ne 'ARRAY'; say for @$a_ref; }
1 2 3 4 5
eval { my $m = ARRAY->new(); print_array_ref_AAA( $m ); }; if( $@ ) { say $@ }
1 2 3 4 5
eval{ my $n = Package_a_ref->new(); print_array_ref_BBB( $n ); }; if ( $@ ) { say $@ }