You can do that by shuffling an array of names and coupling neighbors in the result. I've omitted the file I/O parts for clarity.

This imports an excellent shuffle() function, use List::Util 'shuffle'; This reads an array full of the names with numbers and dot stripped, and then strips newlines, too,

my @friends = map { (split /\./)[1] } <DATA>; chomp @friends;
Shuffle them and stuff them into a hash, which naturally pairs them,
@friends = shuffle @friends; my %couple = (@friends);
Finally, print the pairs,
for (keys %couple) { print "$_ and $couple{$_} are partners\n"; }
Here's the "file" that code reads. To read from a named file, instead, just do as you did above.
__DATA__ 1.bobby 2.jane 3.charleen 4.markus 5.gabriel 6.Alex

Perl data structures and the shuffle function make this a lot easier.

After Compline,
Zaxo


In reply to Re: Random Couple Script by Zaxo
in thread Random Couple Script by gsr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.