Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8860943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:22:45+00:00 2026-06-14T15:22:45+00:00

What is defined by the saying first-class entities and how does it differ from

  • 0

What is defined by the saying “first-class entities” and how does it differ from “second-class entities”?

What does it mean when one says “regexes are first-class entities in modern perl when created with the qr// operator” (taken from Modern Perl: the book).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T15:22:47+00:00Added an answer on June 14, 2026 at 3:22 pm

    As MeNoMore correctly said, a first-class-entity is a data type of the language you can freely assign to variables etc. In Perl, these include:

    • Scalars
    • Arrays
    • Hashes
    • Coderefs (e.g. anonymous subroutines)
    • IO
    • Typeglobs (The symbol table is a hash of globs)
    • Formats

    Those can reside in the symbol table. The scalar slot can be occupied by various other types in addition:

    • Signed integers
    • Unsigned integers
    • Floating point numbers
    • Strings
    • References
    • Regexes

    Some of these entities have built-in constructors into tha language: Number and String literals for scalars, list notation for arrays and hashes, [] and {} for anonymous array- and hashrefs, the sub keyword for code, the open function for IO objects, the format builtin for formats, the reference operator for references, and the qr{} operator for regexes.

    There are language constructs in Perl that are not first-class entities and cannot be assigned to scalars or other first-class entities. For example, packages. This code doesn’t work:

    my $anonymous_package = package { ... };  # XXX
    

    Shell commands have their own builtins, but are no data objects, so this won’t work:

    # don't execute `yes`, but store a handle to it in reference
    my $shell_command = \qx{yes};
    

    Instead, this statement should not terminate (and probably blow your memory).

    Lists in Perl are language constructs, but no data types:

    my $listref = \($x, $y, $z); # assigns reference to $z instead
    

    The builtin types in Perl can have coercion rules:

    • Numbers and Strings coerce back and forth.
    • A single scalar in list context is a list of arity 1.
    • An array in scalar context evaluates to the length of the array
    • An (even valued) array can be assigned to a hash
    • A Hash can be assigned to an array so that assigning this array to another hash would recreate the same hash
    • A Hash in scalar context evaluates to (a) a false value if it is empty or (b) to a string indicating the number of filled and allocated buckets e.g. 1/8 or (c) to the number of keys in numerical context.
    • Regexes in string context evaluate to a pattern string that behaves like the one they were specified with: qr(ab?c) eq "(?-xism:ab?c)", depending on the version of perl.

    Objects can be overloaded to show similar coercion rules through overloading.

    In the case of regex-refs, a scalar containing such a reference can be used interchangeably with a regex literal, e.g. in the pattern

    $string =~ /ab?c/
    

    the regex could be replaced with $regex if $regex is like above:

    my $regex = qr/ab?c/;
    $string =~ $regex ### no dereferencing syntax!
    # $string =~ /$regex/ will work too, but may invoke string overloading first (?)
    

    For example, coderefs require more biolerplate code:

    sub foo {...}
    foo();
    

    versus

    my $foo = sub {...};
    $foo->();  # two possibilities
    &$foo();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason this program is saying that 'switch' is not defined. What is
User Defined Function (UDFs) are functions that one can program and can be dynamically
I defined a global variable that is called from other view and it is
I defined a Window in WPF, into this one I put a stack panel
I'm working on a class that inherits from another class, but I'm getting a
First let me start by saying that I don't have a complete understanding of
I'll preface this by saying this is my first Mac application, though I've been
First for all I would like to start by saying I am relatively new
I've got an azure table record object defined as [DataServiceKey(PartitionKey, RowKey)] public class TableRecord
First off I want to start off saying that I don't know anything about

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.