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 6128765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:39:49+00:00 2026-05-23T16:39:49+00:00

There is a restriction on arrays and hashes as state variables. We can’t initialize

  • 0

There is a restriction on arrays and hashes as state variables. We can’t initialize them in list context as of Perl 5.10:

So

state @array = qw(a b c); #Error!

Why is it so? Why this is not allowed?

We can use state arrays and initialize them by this way

state @numbers;
push @numbers, 5;
push @numbers, 6;

but why not directly do it by state @numbers = qw(5 6);

Why doesn’t Perl allow it?

  • 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-05-23T16:39:50+00:00Added an answer on May 23, 2026 at 4:39 pm

    According to perldiag, support for list context initialization is planned for a future release:

    • Initialization of state variables in list context currently forbidden
      (F) Currently the implementation of “state” only permits the initialization of scalar variables in scalar context. Re-write state ($a) = 42 as state $a = 42 to change from list to scalar context. Constructions such as state (@a) = foo() will be supported in a future perl release.

    According to this message about the change that made this an error:

    For now, forbid all list assignment initialisation of state variables,
    as the precise semantics in Perl 6 are not clear. Better to make it a
    syntax error, than to have one behaviour now, but change it later.
    [I believe that this is the consensus. If not, it will be backed out]

    You could always use an arrayref instead:

    state $arrayRef = [qw(a b c)];
    

    Note that your example of

    state @numbers;
    push @numbers, 5;
    push @numbers, 6;
    

    does not mean the same thing that state @numbers = qw(5 6) would (if it worked). A state variable is only initialized once, but your code would push 5 & 6 onto the array every time that code was executed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a restriction on the complexity of selectors that can be used with
I believe there are restriction of math operation can be performed for GQL. The
Is there a restriction or limit for the number of installed/distributed iPhone applications with
Is there any formal restriction as to which characters are allowed in URL parameter
is there a way to programmatically access the age restriction set in the parental
Is there some restriction in BizTalk 2006 R2 to accessing static methods in external
Short question: How can I modify individual items in a List ? (or more
There can only be one IDENTITY column per table Why is it so? Take
There is big array of entries having the following type: typedef struct { int
C++ Standard 8.3.2/4 says: There shall be no references to references, no arrays of

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.