G'day catfish1116,
Here's a solution which
$ perl -wE ' my @players = qw{Barney Fred Dino}; my @bowled = (195, 205, 30); my %score = map +($players[$_] => $bowled[$_]), 0 .. $#players; say "@players"; say "@score{@players}"; ' Barney Fred Dino 195 205 30
To hopefully avoid wrapping, I changed "bowling_scores" to "bowled". Other than than, I've used the same variable names and data that you presented.
In case you were unaware, the + in "map +(..." disambiguates map followed by an expression in parentheses (wanted) from map followed by a list of parameters in parentheses (not wanted). Try it without the + to see the difference; I get player names but no score values, and 8 warning messages.
Arrays with differing numbers of elements are not addressed here; however, your program should include some sort of validation code to handle that situation.
— Ken
In reply to Re: Working on hash slice
by kcott
in thread Working on hash slice
by catfish1116
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |