Logo

Programming-Idioms

History of Idiom 94 > diff from v33 to v34

Edit summary for version 34 by test:
[Perl] test

Version 33

2018-02-07, 20:31:41

Version 34

2018-10-15, 14:56:45

Idiom #94 Print type of variable

Print the name of the type of x. Explain if it is a static type or dynamic type.

This may not make sense in all languages.

Idiom #94 Print type of variable

Print the name of the type of x. Explain if it is a static type or dynamic type.

This may not make sense in all languages.

Code
print ref($x)||"SCALAR", "\n";
Code
array.pop()
Comments bubble
Example:
my $s = "foo";
my @a = (1,2);
my %h = {foo=>1, bar=>2};
my $o = bless {}, 'OBJECT';
print ref($_)||"SCALAR", "\n" for $s, \@a, \%h, $o;

Output:
SCALAR
ARRAY
HASH
OBJECT
Comments bubble
Example:
my $s = "foo";
my @a = (1,2);
my %h = {foo=>1, bar=>2};
my $o = bless {}, 'OBJECT';
print ref($_)||"SCALAR", "\n" for $s, \@a, \%h, $o;

Output:
SCALAR
ARRAY
HASH
OBJECT