in reply to Vote decider

Hi!
...so it probably doesn't work...
You're right!
#!/usr/bin/perl -w use strict; my @parties = qw(Liberal Conservative NDP Green); my $party = rand(4); print $parties[$party];
This should work.
mawe

Replies are listed 'Best First'.
Re^2: Vote decider
by diotalevi (Canon) on Jun 28, 2004 at 19:07 UTC

    Avoid writing literals like 4 into your source code and use the length of the array as an argument for itself.

    print $parties[ rand @parties ];

    Or.

    my $party_ix = rand @parties; print $parties[ $party_ix ];
      Good point! Thank you!

      mawe