On Aug 22, 5:44 am, [EMAIL PROTECTED] (Chris) wrote:
> I am working a script that is a solution to a problem in Intermediate
> Perl. Here is the script:
>
> #!/usr/bin/perl -w
> use strict;
>
> sub check_items_for_all {
> my $all_ref = @_;
> my @who = keys %$all_ref;
>
> my @required = qw(preserver sunscreen water_bottle jacket);
> my @missing = ( );
>
> for my $crew (@who){
> for my $item(@required){
> unless (grep $item eq $_, %$all_ref{$crew}) {
> print "$crew is missing $item.\n";
> #push @missing, $item;
> }
> }
> }
>
> #if (@missing) {
> # print "Adding @missing to @$items for $who.\n";
> # push @$items, @missing;
> #}
>
> }
You've declared @missing in the wrong scope. It should be inside the
$crew loop.
And unless it is important that the elements of @missing have the same
order as those in @required then you'd be better off doing this with a
hash.
for my $crew (@who) {
my $items = $all_ref->{$crew};
my %missing;
@[EMAIL PROTECTED] = ();
delete @[EMAIL PROTECTED];
# Do stuff with keys %missing
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/