Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Dec 30th, 2011  |  syntax: Perl  |  size: 0.85 KB  |  hits: 51  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #! /usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. use Data::Dumper qw( Dumper );
  7.  
  8. sub splitlist(@)
  9. {
  10.   [@_[0 .. int((($#_ % 2 ) ? $#_ : $#_ - 1) / 2)]],  [@_[int(($#_ + 1) / 2) .. $#_]]
  11. }
  12.  
  13.  
  14. my @empty;
  15. my @oneelement = qw( 1 );
  16. my @odd = qw( 1 2 3 4 5 );
  17. my @even = qw( 1 2 3 4 5 6 );
  18.  
  19. print "empty:\n";
  20. my ($f,$s) = splitlist(@empty);
  21. print "first: " . Dumper($f) . "\n";
  22. print "second: " . Dumper($s) . "\n";
  23.  
  24. print "oneelement:\n";
  25. ($f,$s) = splitlist(@oneelement);
  26. print "first: " . Dumper($f) . "\n";
  27. print "second: " . Dumper($s) . "\n";
  28.  
  29. print "odd:\n";
  30. ($f,$s) = splitlist(@odd);
  31. print "first: " . Dumper($f) . "\n";
  32. print "second: " . Dumper($s) . "\n";
  33.  
  34. print "even:\n";
  35. ($f,$s) = splitlist(@even);
  36. print "first: " . Dumper($f) . "\n";
  37. print "second: " . Dumper($s) . "\n";
  38. ~