[sf-perl] randomize particular lines

Bart Alberti bart at solozone.com
Mon Mar 6 16:05:47 PST 2006


Here is the idea I am working on.
Bart Alberti

------------------------>>>>>>>>>>

#!/usr/bin/perl

#use warnings;
use strict;
my $dictionary = "textfile";
my ($word);
   open (DICT, $dictionary) or die "Cannot open $dictionary: $!";
   my @words = <DICT>;
   foreach (@words)
   {
    chomp($_);
 #   print "$_,\n";  #for debug reason
   }
   if ($_ % 3 == 1){
   $word = $words[rand @words];
    my @scramble = split(//, $word);
   @scramble = sort { (-1,1)[rand 2] } @scramble;
  $word = $scramble; #if this line omitted, prints the whole file unchanged
  }
    foreach (@words) {print "$_\n"};
__END__


More information about the SanFrancisco-pm mailing list