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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:14:20+00:00 2026-06-09T03:14:20+00:00

I am currently reading Intermediate Perl from O’Reilly and am attempting to to do

  • 0

I am currently reading Intermediate Perl from O’Reilly and am attempting to to do one of the exercises. I am new to references in Perl, so I hope that I am not misunderstanding something and coding this exercise incorrectly.

However, I have tried to debug this code and I am not able to come to a conclusion as to how the line with the smart matching is failing every time. From what I understand @array ~~ $scalar should return true if the string-wise scalar value is found in the @array.

Below is my code:

#!/usr/bin/perl -w
use 5.010;

my @rick  = qw(shirt shotgun knife crossbow water);
my @shane = qw(ball jumprope thumbtacks crossbow water);
my @dale  = qw(notebook shotgun pistol pocketprotector);
my %all   = (
    Rick  => \@rick,
    Shane => \@shane,
    Dale  => \@dale,
);

check_items_for_all(\%all);

sub check_items_for_all {
    my $all = shift;
    foreach $person (keys %$all) {
        #print("$person\n");
        $items = $all->{$person};
        #print("@$items");
        check_required_items($person, $items);
    }
}

sub check_required_items {
    my $who      = shift;                #persons name
    my $items    = shift;                #reference to items array
    my @required = qw(water crossbow);
    print(
        "Analyzing $who who has the following items: @$items. Item being compared is $item \n"
    );
    foreach $item (@required) {
        unless (@$items ~~ $item) {
            print "Item $item not found on $who!\n";
        }
    }
}
  • 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-09T03:14:21+00:00Added an answer on June 9, 2026 at 3:14 am

    If you reverse the match it will work:

    $item ~~ @$items
    

    or

    $item ~~ $items  # Smart-matching works with references too.
    

    PS: get used to adding use strict; to the start of your program. It will point you to a few mistakes in your code 🙂

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

Sidebar

Related Questions

I am currently reading Beginning CakePHP:From Novice to Professional by David Golding. At one
I am currently reading information from an input file. Of that information, there is
I'm currently reading Rails 3 In Action. There is code that I was wondering
I'm currently reading Head First's Object Oriented Analysis and Design. The book states that
I'm currently reading Oreilly's Learning XNA 4.0 and I've noticed that the author is
I am currently reading the PostgreSql code. Here is an excerpt from the buffer
I am currently reading about SWT. There is often written, that Eclipse as an
I'm currently reading 'Javascript Web Applications' (O'Reilly, Alex MacCaw) and very early on there's
I am currently reading 'Linux Kernel Development' by Robert Love and I do not
I am currently reading from ActiveMQ with a Message driven bean (EJB3) in the

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.