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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:23:36+00:00 2026-05-26T15:23:36+00:00

print (a..c) # this prints: abc print ($a = abc) # this prints: abc

  • 0
print (a..c) # this prints: abc  
print ($a = "abc") # this prints: abc

print ($a = a..c); # this prints: 1E0

I would have thought it would print: abc

use strict;
print ($a = "a".."c"); # this prints 1E0

Why? Is it just my computer?
edit: I’ve got a partial answer (the range operator .. returns a boolean value in scalar context – thanks) but what I don’t understand is:
why does: print ($a = “a”…”c”) produce 1 instead of 0
why does: print ($a = “a”..”c”) produce 1E0 instead of 1 or 0

  • 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-26T15:23:36+00:00Added an answer on May 26, 2026 at 3:23 pm

    There are a number of subtle things going on here. The first is that .. is really two completely different operators depending on the context in which it’s called. In list context it creates a list of values (incrementing by one) between the given starting and ending points.

    @numbers =  1  ..  3;  # 1, 2, 3
    @letters = 'a' .. 'c'; # a, b, c (Yes, Perl can increment strings)
    

    Because print interprets its arguments in list context

    print 'a' .. 'c';    # <-- this
    print 'a', 'b', 'c'; # <-- is equivalent to this
    

    In scalar context, .. is flip-flop operator. From Range Operators in perlop:

    It is false as long as its left operand is false. Once the left
    operand is true, the range operator stays true until the right operand
    is true, AFTER which the range operator becomes false again.

    Assignment to a scalar value as in $a = ... creates scalar context. That means that the .. in print ($a = 'a' .. 'c') is an instance of the flip-flop operator, not the list creation operator.

    The flip-flop operator is designed to be used when filtering lines in a file. e.g.

    while (<$fh>) {
        print if /first/ .. /last/;
    }
    

    would print all of the lines in a file starting with the one that contained first and ending with the one that contained last.

    The flip-flop operator has some additional magic designed to make it easy to filter based on the line number.

    while (<$fh>) {
        print if 10 .. 20;
    }
    

    will print lines 10 through 20 of a file. It does this by employing special case behavior:

    If either operand of scalar .. is a constant expression, that
    operand is considered true if it is equal (==) to the current input
    line number (the $. variable).

    The strings a and c are both constant expressions so they trigger this special case. They aren’t numbers, but they’re used as numbers (== is a numeric comparison). Perl will convert scalar values between strings and numbers as needed. In this case, both values nummify to 0. Therefore

    print ($a = 'a' .. 'c');             # <-- this
    print ($a = 0 .. 0);                 # <-- is effectively this
    print ($a = ($. == 0) .. ($. == 0)); # <-- which is really this
    

    We’re getting close to the bottom of the mystery. On to the next bit. More from perlop:

    The value returned is either the empty string for false, or a sequence
    number (beginning with 1) for true. The sequence number is reset for
    each range encountered. The final sequence number in a range has the
    string “E0” appended to it

    If you haven’t read any lines from a file yet, $. will be undef which is 0 in a numerical context. 0 == 0 is true, so the .. returns a true value. It’s the first true value, so it’s 1. Because both the left-hand and right-hand sides are true the first true value is also the last true value and the E0 “this is the last value” suffix is appended to the return value. That is why print ($a = 'a' .. 'c') prints 1E0. If you were to set $. to a non-zero value the .. would be false and return the empty string.

    print ($a = 'a' .. 'c'); # prints "1E0"
    $. = 1;
    print ($a = 'a' .. 'c'); # prints nothing
    

    The very final piece of the puzzle (and I might be going too far now) is that the assignment operator returns a value. In this case that’s the value assigned to $a1 — 1E0. This value is what is ultimately spit out by the print.

    1: Technically, the assignment produces a lvalue for the item assigned to. i.e. it returns an lvalue for the variable $a which then evaluates to 1E0.

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

Sidebar

Related Questions

I expected this to print [b] but it prints [] : $x = abc;
suppose I have a String, say: <abc> <xyz> How do I print this in
System.out.println( Arrays.deepToString( abc<def>ghi.split((?:<)|(?:>)) ) ); This prints [abc, def, ghi] , as if I
This is my code: import datetime today = datetime.date.today() print(today) This prints: 2008-11-22 which
I'm wondering why this code section prints out the following: print request.user.has_perm('bug_tracking.is_developer'): + str(request.user.has_perm('bug_tracking.is_developer'))
I have three modules as: one.py : def abc(): print "Heeeeeeeeeeeiiiiiioooooooooo" two.py : import
Why doesn't this print all the passed arguments, in bash? function abc() { echo
Why won't this print success when I submit the form? I'm pretty sure it
I am trying to hide some divs before the user prints this giant form,
def myFunc(arg1, arg2): print This is a test with + arg1 + 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.