jjohhn has asked for the wisdom of the Perl Monks concerning the following question:
anyway I don't understand the syntax error being flagged:
update: changed# sub weighted_hash # chooses and returns a random key from a hash; # the probability of choosing a specific key # is weighted by the value associated with that key sub weighted_hash{ my $hashref = shift; my %hash = $$hashref; my @weighted; foreach my $key (keys %hash){ my $weight = $hash{$key}; while ($weight >0){ push @weighted $key; $weight--; } } rand_elt @weighted; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: "Scalar found where operator expected", references
by dave_the_m (Monsignor) on May 22, 2005 at 00:24 UTC | |
|
Re: "Scalar found where operator expected", references
by fglock (Vicar) on May 21, 2005 at 23:31 UTC | |
|
Re: "Scalar found where operator expected", references
by sh1tn (Priest) on May 22, 2005 at 00:15 UTC | |
|
Re: "Scalar found where operator expected", references
by Roger (Parson) on May 22, 2005 at 09:21 UTC | |
|
Re: "Scalar found where operator expected", references (perl6)
by mrborisguy (Hermit) on May 22, 2005 at 16:35 UTC | |
|
Re: "Scalar found where operator expected", references
by TedPride (Priest) on May 22, 2005 at 16:45 UTC |