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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:37:38+00:00 2026-06-09T07:37:38+00:00

According to Programming Perl , using smartmatch with any on the left and a

  • 0

According to Programming Perl, using smartmatch with “any” on the left and a number on the right checks numeric equality:

------------------------------------------------------------------------------
| Left | Right |    Description    | Like (But Evaluated in Boolean Context) |
------------------------------------------------------------------------------
|  Any |   Num |  Numeric equality |               Any == Num                |

Therefore, I expect the following to output 1:

my @arr = ('aaa');
my $num = 1;
say @arr ~~ $num;

but it actually outputs the empty string.

I thought @arr would be converted to scalar 1 because it has 1 element, so say @arr ~~ $num would be equivalent to say @arr == $num.

Why is @arr ~~ $num different from @arr == $num?

  • 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-09T07:37:39+00:00Added an answer on June 9, 2026 at 7:37 am

    The smartmatch operator obviously doesn’t take lists as operands. As such, it evaluates its operands in scalar context. If that was the end of the story, the following wouldn’t work

    my @a = ('aaa', 'bbb');
    my $s = 'aaa';
    say $s ~~ @a;
    

    because it would be the same as

    say 'aaa' ~~ 2;
    

    But it’s clear that it does work. That’s because smartmatch automatically creates a reference to its operands that are arrays or hashes, just like push does to its first operand. That means

    say $s ~~ @a;
    

    is really

    say $s ~~ \@a;
    

    and (your code)

    say @a ~~ $n;
    

    is the same as

    say \@a == $n;
    

    You need to get the length explicitly. The following will do what you want:

    say 0+@a ~~ $n;
    

    Of course, so would

    say 0+@a == $n;
    

    or even

    say @a == $n;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I finished my first C++ programming assignment and received my grade. But according
I am using structures in my programming and I sort the structure according to
According to the OpenMP web site OpenMp is the de-facto standard for parallel programming
I have used emacs for erlang programming. According to http://emacswiki.org/emacs/CompileCommand , I have configure
According to the book Programming Clojure refs manage coordinated, synchronous changes to shared state
According to URL Loading System Programming Guide NSConnection sample code I can release connection
I am currently starting out with programming micro controllers using C30 (A C compiler
According to wikipedia : functional programming is a programming paradigm that treats computation as
According to John C. Mitchell - Concepts in programming languages, [...] Java guarantees that
im programming a app to perform CRUD to any given table in any given

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.