On 8/22/07, Chris <[EMAIL PROTECTED]> 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; > #} > } > > my @gilligan = qw(red_shirt hat lucky_socks water_bottle); > my @skipper = qw(blue_shirt hat jacket preserver sunscreen); > my @professor = qw(sunscreen water_bottle slide_rule batteries radio); > > my %all = ( > Gilligan => [EMAIL PROTECTED], > Skipper => [EMAIL PROTECTED], > Professor => [EMAIL PROTECTED], > ); > > check_items_for_all(\%all); > > When I run the script, I get the following error message: > syntax error at required_items.pl line 13, near "$all_ref{" > syntax error at required_items.pl line 18, near "}" > > I'm not sure what is causing this. Eventually, I want the script to > access each crew member's belongings, figure out which of the items in > the @required array are missing, and place those items in the member's > array. Any hints? > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > http://learn.perl.org/ > > >
http://perldoc.perl.org/functions/grep.html Without testing the code or anything, could it be that: > unless (grep $item eq $_, %$all_ref{$crew}) { should be: unless (grep $item eq %$all_ref{$crew}) { ? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/