Posted By

heinz1959 on 06/11/10


Tagged

textmate lines Unsort


Versions (?)

Unsort Lines TextMate Command


 / Published in: Perl
 

URL: http://www.commandlinefu.com/commands/view/4401/randomize-lines-opposite-of-sort

Need to "unsort" / randomize / scramble LINES in a text? Copy source -> then TextMate Bundle Editor -> New Command -> select all in Command(s) -> paste source -> Input: Selected Text or Document -> Output: Replace Selected Text ...

  1. #!/usr/bin/perl -wl
  2.  
  3. @f=<>;
  4.  
  5. for $i (0 .. $#f) {
  6. $r=int rand ($i+1);
  7. @f[$i, $r]=@f[$r,$i] if ($i!=$r);
  8. }
  9.  
  10. chomp @f;
  11.  
  12. print join $/, @f;

Report this snippet  

You need to login to post a comment.