Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Re: random elements from array - new twist

by perlguy (Deacon)
on Nov 05, 2002 at 23:30 UTC ( #210605=note: print w/replies, xml ) Need Help??


in reply to Re: random elements from array - new twist
in thread random elements from array - new twist

Forgive me, but why are you setting $a like this:
$a = $_ + rand @{$r} - $_ and #...

It seems to me that it should simply be:
$a = rand @{$r} and #...

Just a bit confused is all... clarify?

Replies are listed 'Best First'.
Re: Re: Re: random elements from array - new twist
by jsprat (Curate) on Nov 05, 2002 at 23:52 UTC
    It got me too (see Re: Re: Re: Re: random elements from array - new twist)... It's a matter of precedence. Have a look at how perl parses it:

    perl -MO=Deparse,-p -e "$a = $_ + rand @{$r} - $_" ($a = ($_ + rand((@{$r;} - $_)))); ^^ ^^ -e syntax OK

    The '- $_' is part of the argument to rand, not the assignment to $a.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://210605]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2020-10-31 23:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (291 votes). Check out past polls.

    Notices?