Search notes:

Perl function: ref

#
#   Compare ref with Scalar::Util->reftype ( https://github.com/ReneNyffenegger/PerlModules/blob/master/Scalar/Util/reftype.pl )
#
use warnings;
use strict;
use feature 'say';

my %H = (1 => 'one', 2 => 'two', 3 => 'three');
my @A = qw(foo bar baz);
my $S = 'A scalar';


# ref returns a non empty string if the argument is a reference. In the
# following three calls, the argument is not a reference, hence, say says nothing:

say ref(%H);
# 

say ref(@A);
#

say ref($S);
#

# In the following three calls, the argument is indeed a reference, hence
# something is said:

say ref(\%H);
# HASH

say ref(\@A);
# ARRAY

say ref(\$S);
# SCALAR

open (my $G, '<', $0);
say ref($G);
# GLOB

# ----------

my $CodeRef = \&F;
say ref($CodeRef);
# CODE

my $RegExp = qr/.*/;
say ref($RegExp);
# Regexp


sub F {

}
Github repository about-perl, path: /functions/ref.pl

See also

Perl functions
reftype() in module Scalar::Util

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1759415197, '216.73.216.42', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/Perl/functions/ref(94): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78