Win has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I’m seeking guidance. I am having problems with the following bit of code:
my $random_string = join '', shuffle split //, "stringtorandomise36let +terslong123456";
It gives me the following error message:
syntax error at Test_flat_file_write_over.pl line 137, near "shuffle s +plit" Execution of Test_flat_file_write_over.pl aborted due to compilation e +rrors.
I'm possibly missing a module reference.

Replies are listed 'Best First'.
Re: shuffle split
by prasadbabu (Prior) on Jan 31, 2006 at 12:15 UTC

    Win, there is no 'shuffle' function in core perl, you can make use of List::Util to accomplish your job.

    use List::Util shuffle; my $random_string = join '', shuffle split //, "stringtorandomise36let +terslong123456"; print "$random_string"; output: le663snetnlrodt1mer23trsogiions4atg5

    Prasad

Re: shuffle split
by blazar (Canon) on Jan 31, 2006 at 12:11 UTC
    $ perldoc -f shuffle No documentation for perl function `shuffle' found

    You either have to roll your own shuffle() sub or use one from a suitable module. Please be sure to check the faq since as you can imagine the question comes out quite often. In case of doubt try perldoc -q shuffle.

Re: shuffle split
by szbalint (Friar) on Jan 31, 2006 at 12:17 UTC

    From perldoc -q shuffle:

    How do I shuffle an array randomly?

    If you either have Perl 5.8.0 or later installed, or if you have Scalar-List-Utils 1.03 or later installed, you can say:

    use List::Util 'shuffle'; @shuffled = shuffle(@list);
Re: shuffle split
by marto (Cardinal) on Jan 31, 2006 at 12:17 UTC
    Win,

    I suspect you want to use List::Util by adding use List::Util qw(shuffle); to the top of your code. However, as I have pointed out to you in previous nodes, you would have found the answer yourself had you used Super Search prior to posting.

    Martin
    A reply falls below the community's threshold of quality. You may see it by logging in.