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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:46:35+00:00 2026-06-07T21:46:35+00:00

Would be someone please to explain the next: In the Programming Perl book postfix

  • 0

Would be someone please to explain the next:

In the “Programming Perl” book postfix autoincrement operator is described, as

when placed after, they ($a-- , $a++) increment or decrement the variable after returning the value.

So, as I understood, $a++ is never used in void context, cause there has been said that

they increment or decrement the variable

But in the next example value of the variable never changes:

my $a = 3;
$a = $a++;
say $a; #always outputs 3

So my assumption is that there is no reason to use post-autoincrement when value is assigned to the same variable, but then the definition from the “Programming Perl” should be considered wrong, cause operator does not affect variable, but value in variable (at least in that example). Is that right?

Appreciation in advance.

  • 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-07T21:46:37+00:00Added an answer on June 7, 2026 at 9:46 pm

    Why, both postfix autoincrement and autodecrement operators are actually quite often used in void context exactly because they affect the variable – not the value.

    Your example works the way it works because variable gets post-incremented before its old value gets assigned to it. In other words, the order of

    my $a = 3; $a = $a++; 
    

    …is…

    1) $old_value = $a;
    2) $a = $a + 1;
    3) $a = $old_value;
    

    Should you replace $a = $a++ with $b = $a++ in your example, and print values of $b and $a afterwards, you’ll clearly see the difference: while $a becomes incremented (thus, equal to 4), $b gets assigned the old value of $a (3).

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

Sidebar

Related Questions

Could someone please explain when would I want to use delegation instead of inheritance?
Can someone please explain me why would a UDP Server not need to use
I would like to access a MySQL database using PHP. Can someone please explain
Would someone please be able to explain to me how to properly install JavaMail
private final String[] okFileExtensions = new String[] { csv }; Would someone please explain
Would someone please explain the difference? Are these the same product, and if not
I googled and got only a few articles about MEF. Would someone please explain
Can someone please explain to me how you would create a star schema starting
I'm clearly missing something. Could someone please explain why this would happen? #define RANDOM_DEVICE
would someone please explain why select len(0x0a000b) returns 3? does len count bytes? and

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.