W
walterbyrd
This is from the perl objects book.
my @required = qw(preserver sunscreen water_bottle jacket);
my @skipper = qw(blue_shirt hat jacket preserver sunscreen);
for my $item (@required) {
unless (grep $item eq $_, @skipper) { # not found in list?
print "skipper is missing $item.\n";
}
}
I don't understand this line:
unless (grep $item eq $_, @skipper)
I understand that $item is each item in the @required array. I am
guessing that the @required array is what is being grep'd. But what is
$_ ? Is that also each item from the @required array? If so, why not
just use the $item variable again? And what does >>$_, @skipper<<
mean? What is with the comma? Is that supposed to mean: grep $item
@skipper?
Is this supposed to check if the skipper is missing any required item?
Why not:
unless (grep $item @required eq grep $item @skipper)
my @required = qw(preserver sunscreen water_bottle jacket);
my @skipper = qw(blue_shirt hat jacket preserver sunscreen);
for my $item (@required) {
unless (grep $item eq $_, @skipper) { # not found in list?
print "skipper is missing $item.\n";
}
}
I don't understand this line:
unless (grep $item eq $_, @skipper)
I understand that $item is each item in the @required array. I am
guessing that the @required array is what is being grep'd. But what is
$_ ? Is that also each item from the @required array? If so, why not
just use the $item variable again? And what does >>$_, @skipper<<
mean? What is with the comma? Is that supposed to mean: grep $item
@skipper?
Is this supposed to check if the skipper is missing any required item?
Why not:
unless (grep $item @required eq grep $item @skipper)