[LON-CAPA-users] List::Util

Seema Ali sali at vsb.bc.ca
Fri Nov 23 09:53:12 EST 2012

Sorry that was a dumb question.  I'm not that much of a Perl programmer.

When I need a shuffle function I use a modified version of:
 sub fisher_yates_shuffle {
        my $deck = shift;  # $deck is a reference to an array
        my $i = @$deck;
        while ($i--) {
            my $j = int rand ($i+1);
            @$deck[$i,$j] = @$deck[$j,$i];

    # shuffle my mpeg collection
    my @mpeg = <audio/*/*.mp3>;
    fisher_yates_shuffle( \@mpeg );    # randomize @mpeg in place
    print @mpeg;  

from: http://perl.active-venture.com/pod/perlfaq4-dataarrays.html

for first, you might try something like:
    @blues = qw/azure cerulean teal turquoise lapis-lazuli/;
    %is_blue = ();
    for (@blues) { $is_blue{$_} = 1 }  

I've never used first before so I'm not sure if that'll help or not.  The code is found on the same page.

I hope that helps.

>From Seema.
From: lon-capa-users-bounces at mail.lon-capa.org [lon-capa-users-bounces at mail.lon-capa.org] on behalf of Gerd Kortemeyer [korte at lite.msu.edu]
Sent: 23 November 2012 05:20
To: Discussion list for LON-CAPA users
Subject: Re: [LON-CAPA-users] List::Util


On Nov 23, 2012, at 7:56 AM, Peter Dencker <dencker at math.uni-luebeck.de> wrote:

> Hi, can one use the functions defined in List::Util ?
> I tried
> <problem>
> <script type="loncapa/perl">
> use List::Util qw(first shuffle);
> </script>
> </problem>
> and this crashed.

"Use" in general is not supported in scripting environment, since many libraries involve and allow I/O.

- Gerd.
LON-CAPA-users mailing list
LON-CAPA-users at mail.lon-capa.org

More information about the LON-CAPA-users mailing list