catfish1116 has asked for the wisdom of the Perl Monks concerning the following question:
Trying out an exercise that uses dereferencing Below is code and error
#! /usr/bin/perl use v5.16.3; use strict; use warnings; ## 7/31/19 ## program uses derefence to simplify subroutine from previous program sub check_required_items { my ($who, $items) = @_; my %whos_items = map { $_, 1 } @$items; # the rest are the person +'s items my @required = qw(preserver sunscreen water_bottle jacket); for my $item (@required) { unless ( $whos_items{$item} ) { # not found in list print "$who is missing $item, \n"; } } } my @gilligan = qw(red_shirt hat lucky_socks water_bottle); check_required_items('gilligan', @gilligan); my @skipper = qw(blue_shirt hat jacket preserver sunscreen); my @professor = qw(sunscreen water_bottle slide_rule batteries radi +o); check_required_items('skipper', @skipper); check_required_items('professor', @professor); Can't use string ("red_shirt") as an ARRAY ref while "strict refs" in +use at ./Page_42 line 12.
TIA The Catfish
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Using Dereferencing
by Fletch (Bishop) on Jul 31, 2019 at 17:50 UTC | |
Re: Using Dereferencing
by soonix (Chancellor) on Jul 31, 2019 at 18:19 UTC | |
Re: Using Dereferencing
by BillKSmith (Monsignor) on Jul 31, 2019 at 18:26 UTC | |
Re: Using Dereferencing
by AnomalousMonk (Archbishop) on Jul 31, 2019 at 19:25 UTC | |
Re: Using Dereferencing
by TieUpYourCamel (Scribe) on Dec 12, 2019 at 21:28 UTC |